mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-12 11:10:35 +00:00
f8979fe7af
* golint and minor changes to make code readable
21 lines
448 B
Go
21 lines
448 B
Go
package pubsub
|
|
|
|
// Publisher sends events to subscribers
|
|
type Publisher struct {
|
|
subs []Subscriber
|
|
}
|
|
|
|
// Send iterates over each subscriber and checks
|
|
// if they are interested in the Event
|
|
// By looking at their topics, if they are then
|
|
// the event is emitted to them
|
|
func (p *Publisher) Send(e Event) error {
|
|
for _, sub := range p.subs {
|
|
for _, topic := range sub.Topics() {
|
|
if e.Type == topic {
|
|
sub.Emit(e)
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|