| 1 |
package partybus |
| 2 |
|
| 3 |
var nextID int64 |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
var _ Unsubscribable = (*Subscription)(nil) |
| 8 |
|
| 9 |
type SubscriptionId int64 |
| 10 |
|
| 11 |
type Subscription struct { |
| 12 |
id SubscriptionId |
| 13 |
bus *Bus |
| 14 |
|
| 15 |
|
| 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 |
|
| 31 |
|
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
func (s *Subscription) Unsubscribe() error { |
| 36 |
return s.bus.Unsubscribe(s) |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
func (s *Subscription) Events() <-chan Event { |
| 58 |
return s.receiver |
| 59 |
} |