Debian Codegraph @

subscription.go

raw symbols SCIP
1 package partybus
2
3 var nextID int64
4
5 // type EventCallback func(Event)
6
7 var _ Unsubscribable = (*Subscription)(nil)
8
9 type SubscriptionId int64
10
11 type Subscription struct {
12 id SubscriptionId
13 bus *Bus
14 // allCallback []EventCallback
15 // selectCallback map[EventType]EventCallback
16 sender chan<- Event
17 receiver <-chan Event
18 eventTypes []EventType
19 }
20
21 func newSubscription(bus *Bus, eventKinds []EventType) *Subscription {
22 nextID++
23 sender, receiver := newQueue()
24 return &Subscription{
25 id: SubscriptionId(nextID),
26 bus: bus,
27 sender: sender,
28 receiver: receiver,
29 eventTypes: eventKinds,
30 // allCallback: make([]EventCallback, 0),
31 // selectCallback: make(map[EventType]EventCallback),
32 }
33 }
34
35 func (s *Subscription) Unsubscribe() error {
36 return s.bus.Unsubscribe(s)
37 }
38
39 // func (s *Subscription) Register(callback EventCallback, eTypes ...EventType) error {
40
41 // if len(eTypes) == 0 {
42 // s.allCallback = append(s.allCallback, callback)
43 // go func() {
44 // for event := range s.receiver {
45 // for c := range s.allCallback {
46 // s.allCallback(event)
47 // }
48 // }
49 // }()
50 // } else {
51 // s.selectCallback[eType]
52 // }
53
54 // return nil
55 // }
56
57 func (s *Subscription) Events() <-chan Event {
58 return s.receiver
59 }