zinx icon indicating copy to clipboard operation
zinx copied to clipboard

时间轮调用问题

Open ghost opened this issue 5 years ago • 1 comments

ghost avatar Aug 10 '19 05:08 ghost

先要初始化 如:

var Scheduler *ztimer.TimerScheduler

func init() {
	Scheduler = ztimer.NewAutoExecTimerScheduler()
}

然后注册方法如下:
f1 := ztimer.NewDelayFunc(func(v ...interface{}) {
  log.Println("aaaaaa")
}, []interface{}{})

f2 := ztimer.NewDelayFunc(func(v ...interface{}) {
    log.Println("bbbbbb")
}, []interface{}{})

Scheduler.CreateTimerAfter(f1, time.Duration(3)*time.Second)
Scheduler.CreateTimerAfter(f2, time.Duration(5)*time.Second)

3秒后打印 aaaaaa 5秒后打印 bbbbbb

yilinershi avatar Oct 21 '20 04:10 yilinershi