Add example for idle
This commit is contained in:
19
idle/idle.go
19
idle/idle.go
@ -37,17 +37,16 @@ func CreateIdler(timeout time.Duration) Idler {
|
||||
for {
|
||||
if i.active.Load() != 0 {
|
||||
time.Sleep(timeout)
|
||||
} else {
|
||||
t := *i.lastTick.Load()
|
||||
now := time.Now()
|
||||
dur := t.Add(timeout).Sub(now)
|
||||
if dur == dur.Abs() {
|
||||
time.Sleep(dur)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
t := *i.lastTick.Load()
|
||||
now := time.Now()
|
||||
dur := t.Add(timeout).Sub(now)
|
||||
if dur == dur.Abs() {
|
||||
time.Sleep(dur)
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
close(i.c)
|
||||
}()
|
||||
|
Reference in New Issue
Block a user