You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
500 B

2 years ago
/**
* @Auth:ShenZ
* @Description:
* @CreateDate:2022/06/15 17:27:35
*/
package utils
import (
"time"
)
type TimerFunc func(interface{}) bool
/**
delay
tick
fun
param
**/
func Timer(delay, tick time.Duration, fun TimerFunc, param interface{}) {
go func() {
if fun == nil {
return
}
t := time.NewTimer(delay)
for {
select {
case <-t.C:
if fun(param) == false {
return
}
t.Reset(tick)
}
}
}()
}