-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasker.go
59 lines (46 loc) · 982 Bytes
/
tasker.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package yotei
import (
"time"
)
type Tasker interface {
Handler
Duration() time.Duration
Weight() uint64
Lock()
Unlock()
IsLocked() bool
IsConcurrent() bool
}
// A list of actionable tasks
type Tasks []Tasker
// Determines that the task can take unlimited duration.
var DurationUnlimited time.Duration = 0
// Weight returns the sum of all he
// weights of all the tasks in the list.
func (tasks Tasks) Weight() uint64 {
total := uint64(0)
for _, task := range tasks {
total += task.Weight()
}
return total
}
// Unlocked returns the tasks that are unlocked
func (tasks Tasks) Unlocked() Tasks {
unlocked := make(Tasks, 0)
for _, task := range tasks {
if !task.IsLocked() {
unlocked = append(unlocked, task)
}
}
return unlocked
}
// Locked returns the tasks that are locked
func (tasks Tasks) Locked() Tasks {
locked := make(Tasks, 0)
for _, task := range tasks {
if task.IsLocked() {
locked = append(locked, task)
}
}
return locked
}