-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispatch.go
More file actions
31 lines (27 loc) · 870 Bytes
/
dispatch.go
File metadata and controls
31 lines (27 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Package dispatch provides a simple event-like concurrent way of listening to
// and emitting event-like messages.
// The basic idea is to have "things" (other packages) that provide a
// PackageDescription which defines which events trigger which callbacks.
// Those callbacks can be handled in the thing itself by implementing an eventLoop
// listening on the EventChannel of dispatch or by dispatch itself
package dispatch
var listener map[string][]chan EventMessage
var control chan ControlMessage
var events chan EventMessage
func init() {
listener = make(map[string][]chan EventMessage)
control = make(chan ControlMessage)
events = make(chan EventMessage)
// start listening queue in separate routine
go startListen()
}
func startListen() {
for {
select {
case c := <-control:
processControl(c)
case e := <-events:
processEvent(e)
}
}
}