-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtimer_default_test.go
More file actions
40 lines (36 loc) · 915 Bytes
/
timer_default_test.go
File metadata and controls
40 lines (36 loc) · 915 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
package timer
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Test_DefaultTimer(t *testing.T) {
require.NotNil(t, DefaultTimer())
require.Equal(t, int64(DefaultTickMs), TickMs())
require.Equal(t, DefaultWheelSize, WheelSize())
require.GreaterOrEqual(t, TaskCounter(), int64(0))
}
func ExampleDefaultTimer() {
fmt.Println(Started())
Start()
_, _ = AfterFunc(100*time.Millisecond, func() {
fmt.Println(100)
})
canceledTaskThenAddAgain := NewTask(1100 * time.Millisecond).WithJobFunc(func() {
fmt.Println("canceled then add again")
})
_ = AddTask(canceledTaskThenAddAgain)
canceledTaskThenAddAgain.Cancel()
_ = AddDerefTask(NewTask(1025 * time.Millisecond).WithJobFunc(func() {
fmt.Println(200)
}))
_ = AddTask(canceledTaskThenAddAgain)
time.Sleep(time.Second + time.Millisecond*200)
Stop()
// Output:
// true
// 100
// 200
// canceled then add again
}