generated from msb_47094/GinChat
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
37 lines
500 B
10 months 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)
|
||
|
}
|
||
|
}
|
||
|
}()
|
||
|
}
|