WIP: Enter/Exit won't work :(

This commit is contained in:
Balakrishnan Balasubramanian 2023-09-08 19:35:58 -04:00
parent b5588989de
commit 8ca82581fe

View File

@ -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()