-
Notifications
You must be signed in to change notification settings - Fork 11
/
task.go
46 lines (38 loc) · 976 Bytes
/
task.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
package gotaskflow
// Basic component of Taskflow
type Task struct {
node *innerNode
}
// Precede: Tasks all depend on *this*.
// In Addition, order of tasks is correspond to predict result, ranging from 0...len(tasks)
func (t *Task) Precede(tasks ...*Task) {
if cond, ok := t.node.ptr.(*Condition); ok {
for i, task := range tasks {
cond.mapper[uint(i)] = task.node
}
}
for _, task := range tasks {
t.node.precede(task.node)
}
}
// Succeed: *this* deps on tasks
func (t *Task) Succeed(tasks ...*Task) {
for _, task := range tasks {
task.node.precede(t.node)
}
}
func (t *Task) Name() string {
return t.node.name
}
// Priority sets task's sche priority. Noted that due to goroutine concurrent mode, it can only assure task schedule priority, rather than its execution.
func (t *Task) Priority(p TaskPriority) *Task {
t.node.priority = p
return t
}
// Task sche priority
type TaskPriority uint
const (
HIGH = TaskPriority(iota + 1)
NORMAL
LOW
)