1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-26 20:15:26 -05:00

unified task package

This commit is contained in:
Darien Raymond
2018-05-27 13:02:29 +02:00
parent 7fa4bb434b
commit 13f3c356ca
21 changed files with 252 additions and 66 deletions

View File

@@ -0,0 +1,30 @@
package task_test
import (
"testing"
"time"
. "v2ray.com/core/common/task"
. "v2ray.com/ext/assert"
"v2ray.com/core/common"
)
func TestPeriodicTaskStop(t *testing.T) {
assert := With(t)
value := 0
task := &Periodic{
Interval: time.Second * 2,
Execute: func() error {
value++
return nil
},
}
common.Must(task.Start())
time.Sleep(time.Second * 5)
common.Must(task.Close())
assert(value, Equals, 3)
time.Sleep(time.Second * 4)
assert(value, Equals, 3)
}