-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.go
43 lines (33 loc) · 992 Bytes
/
handler.go
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
32
33
34
35
36
37
38
39
40
41
42
43
package events
import (
"sync"
bitmask "github.com/theTardigrade/golang-infiniteBitmask"
)
// HandlerOrder is used in the AddOptions struct
// to determine whether a handler will be called
// before or after another: lower values get
// called first.
type HandlerOrder int
// HandlerFunc is used as the type of the function
// that will be called when a relevant event is run.
type HandlerFunc func()
type handlerDatum struct {
// constant
order HandlerOrder
handler HandlerFunc
shouldWaitTillDone bool
// mutable
bitmaskValue *bitmask.Value
isRunning bool
isRunPending bool
mainMutex sync.Mutex
// constant
doneChan chan struct{}
// mutable
donePendingCount int
doneMutex sync.Mutex
}
type handlerData []*handlerDatum
func (d handlerData) Len() int { return len(d) }
func (d handlerData) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
func (d handlerData) Less(i, j int) bool { return (d[j].order - d[i].order) > 0 }