summaryrefslogtreecommitdiff
path: root/plugins/events/broadcaster.go
blob: 778b307d7ff457f0cc402b353ea39c2b3710eac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package events

type EventListener interface {
	Handle(event interface{})
}

type EventBroadcaster struct {
	listeners []EventListener
}

func NewEventBroadcaster() *EventBroadcaster {
	return &EventBroadcaster{}
}

func (eb *EventBroadcaster) AddListener(l EventListener) {
	// todo: threadcase
	eb.listeners = append(eb.listeners, l)
}

func (eb *EventBroadcaster) Push(e interface{}) {
	for _, l := range eb.listeners {
		l.Handle(e)
	}
}