File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ lotteryStream.Broadcast(everyoneLosesEvent)
45
45
```
46
46
47
47
### Auto subscribe certain routes to topics
48
- ` Stream ` implements an ` http.Handler ` but by default just registers clients for broadcasts.
48
+ ` Stream ` implements an ` http.Handler ` but by default just registers clients for broadcasts.
49
49
50
50
Use ` TopicHandler ` to create another handler for that stream that will subscribe clients to topics as well as broadcasts.
51
51
``` go
@@ -94,7 +94,7 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request) {
94
94
http.Error (...)
95
95
return
96
96
}
97
-
97
+
98
98
client.Wait ()
99
99
}
100
100
```
@@ -149,7 +149,7 @@ typeFact := &eventsource.EventTypeFactory{
149
149
// then with incrementing ID's
150
150
idFact := &eventsource.EventIdFactory {
151
151
Next : 0 ,
152
- NewFunc : typeFact. New ,
152
+ NewFact : typeFact,
153
153
}
154
154
155
155
// then generate as many events as you want with
Original file line number Diff line number Diff line change @@ -14,7 +14,10 @@ type EventFactory interface {
14
14
// sequential ID fields.
15
15
// If NewFunc is set, the factory uses it to create events before setting
16
16
// their IDs
17
+ // If NewFunc is not set, NewFact will be used. If neither is set, a new
18
+ // event is created from scratch
17
19
type EventIdFactory struct {
20
+ NewFact EventFactory
18
21
NewFunc func () * Event
19
22
Next uint64
20
23
}
@@ -24,6 +27,8 @@ func (f *EventIdFactory) New() *Event {
24
27
var e * Event
25
28
if f .NewFunc != nil {
26
29
e = f .NewFunc ()
30
+ } else if f .NewFact != nil {
31
+ e = f .NewFact .New ()
27
32
} else {
28
33
e = & Event {}
29
34
}
@@ -35,17 +40,22 @@ func (f *EventIdFactory) New() *Event {
35
40
36
41
// EventTypeFactory creates events of a specific type
37
42
type EventTypeFactory struct {
43
+ NewFact EventFactory
38
44
NewFunc func () * Event
39
45
Type string
40
46
}
41
47
42
48
// New creates an event with the event type set
43
49
// If NewFunc is set, the factory uses it to create events before setting
44
50
// their event types
51
+ // If NewFunc is not set, NewFact will be used. If neither is set, a new
52
+ // event is created from scratch
45
53
func (f * EventTypeFactory ) New () * Event {
46
54
var e * Event
47
55
if f .NewFunc != nil {
48
56
e = f .NewFunc ()
57
+ } else if f .NewFact != nil {
58
+ e = f .NewFact .New ()
49
59
} else {
50
60
e = & Event {}
51
61
}
You can’t perform that action at this time.
0 commit comments