WIP: Enter/Exit won't work :(
This commit is contained in:
parent
b5588989de
commit
8ca82581fe
22
idle/idle.go
22
idle/idle.go
@ -2,10 +2,32 @@
|
||||
package idle
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
gIdler atomic.Pointer[idler]
|
||||
)
|
||||
|
||||
func Wait(timeout time.Duration) error {
|
||||
i := CreateIdler(timeout).(*idler)
|
||||
ok := gIdler.CompareAndSwap(nil, i)
|
||||
if !ok {
|
||||
return fmt.Errorf("idler already waiting")
|
||||
}
|
||||
i.Wait()
|
||||
return nil
|
||||
}
|
||||
|
||||
func Tick() {
|
||||
i := gIdler.Load()
|
||||
if i != nil {
|
||||
i.Tick()
|
||||
}
|
||||
}
|
||||
|
||||
type Idler interface {
|
||||
Enter()
|
||||
Exit()
|
||||
|
Loading…
Reference in New Issue
Block a user