-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtask.go
More file actions
47 lines (39 loc) · 1009 Bytes
/
task.go
File metadata and controls
47 lines (39 loc) · 1009 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 _, task := range tasks {
index := len(cond.mapper)
cond.mapper[uint(index)] = 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
)