mirror of
https://github.com/vacp2p/dasy.git
synced 2026-01-08 22:37:59 -05:00
* started working on payload concept * added crypto * moved into new package, added feed * added nicer feed stuff * minor readme for now * subscribe implemented badly * doc * doc block * cleaned up a little * making a mutex * mock, empty test * test wrapper * started playing around * updated mock * formatted * updated * updated interface * updated * updated * updated mock, rewrote test stuff * todos * added tests * reuse * dont need var
21 lines
500 B
Go
21 lines
500 B
Go
package event
|
|
|
|
type Subscription chan <-Payload
|
|
|
|
type Feed struct {
|
|
subscribers []Subscription
|
|
}
|
|
|
|
// Subscribe adds a channel to the feed.
|
|
func (f *Feed) Subscribe(channel Subscription) { // @todo think about returning a subscription like prysm
|
|
f.subscribers = append(f.subscribers, channel)
|
|
}
|
|
|
|
// Send sends a payload to all the subscribers for the specific feed.
|
|
func (f *Feed) Send(value Payload) {
|
|
// @todo is this good enough for now?
|
|
for _, sub := range f.subscribers {
|
|
sub <- value
|
|
}
|
|
}
|