-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.go
44 lines (35 loc) · 795 Bytes
/
util.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
44
package main
import "sort"
type servicesByPriority []*Service
func (s servicesByPriority) Len() int { return len(s) }
func (s servicesByPriority) Less(i, j int) bool { return s[i].Config.Priority < s[j].Config.Priority }
func (s servicesByPriority) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s servicesByPriority) Sort() { sort.Stable(s) }
type quit struct {
stop chan bool
stopped chan bool
}
func newQuit() *quit {
return &quit{
stop: make(chan bool, 1),
stopped: make(chan bool, 1),
}
}
func (q *quit) sendStop() {
select {
case q.stop <- true:
default:
}
}
func (q *quit) sendStopped() {
select {
case q.stopped <- true:
default:
}
}
func (q *quit) waitForStop() {
<-q.stop
}
func (q *quit) waitForStopped() {
<-q.stopped
}