12345678910111213141516171819202122232425262728 |
- package util
- import "sync"
- // CheckOnce struct
- type CheckOnce struct {
- mutex sync.Mutex
- done bool
- }
- // IsDone func
- func (c *CheckOnce) IsDone() bool {
- c.mutex.Lock()
- defer c.mutex.Unlock()
- return c.done
- }
- // Done func
- func (c *CheckOnce) Done(f func()) {
- c.mutex.Lock()
- defer c.mutex.Unlock()
- if !c.done {
- f()
- c.done = true
- }
- }
|