-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelayqueue_test.go
More file actions
61 lines (52 loc) · 805 Bytes
/
delayqueue_test.go
File metadata and controls
61 lines (52 loc) · 805 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package quartz
import (
"fmt"
"testing"
"time"
)
type item struct {
expire time.Duration
cycle bool
fn func()
}
func (i *item) GetDelay() time.Duration {
return i.expire
}
func (i *item) Cycle() bool {
return i.cycle
}
func TestQueue(t *testing.T) {
queue := NewDelayQueue()
go func() {
func() {
for {
select {
case it, ok := <-queue.Poll():
if !ok {
return
}
it.(*item).fn()
}
}
}()
fmt.Println(queue.Len())
}()
queue.Offer(&item{
expire: time.Millisecond * 10,
cycle: false,
fn: func() {
fmt.Println("ok")
},
})
for i := 0; i < 1000; i++ {
queue.Offer(&item{
expire: time.Millisecond * 10,
cycle: false,
fn: func() {
},
})
}
time.Sleep(time.Second * 2)
queue.Close()
time.Sleep(time.Second * 1)
}