-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (35 loc) · 643 Bytes
/
Copy pathmain.go
File metadata and controls
41 lines (35 loc) · 643 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
package main
import (
"fmt"
"goConcurrencyTaskScheduler/scheduler"
"time"
)
func main() {
s := scheduler.NewScheduler(1)
time.Sleep(50 * time.Millisecond)
for _, t := range []struct {
id string
priority int
}{
{"p10", 10},
{"p1", 1},
{"p20", 20},
{"p5", 5},
} {
id := t.id
priority := t.priority
fmt.Println("SUBMIT", id, "priority", priority)
s.Submit(scheduler.Task{
ID: id,
Priority: priority,
Timeout: 2 * time.Second,
ExecFunc: func() error {
fmt.Println("RUN", id)
time.Sleep(200 * time.Millisecond)
return nil
},
})
}
time.Sleep(3 * time.Second)
s.Stop()
}