Do handles once logic.
(f func())
| 29 | |
| 30 | // Do handles once logic. |
| 31 | func (o *Once) Do(f func()) { |
| 32 | if atomic.LoadUint32(&o.done) == 1 { |
| 33 | return |
| 34 | } |
| 35 | // Slow-path. |
| 36 | o.m.Lock() |
| 37 | defer o.m.Unlock() |
| 38 | if o.done == 0 { |
| 39 | defer atomic.StoreUint32(&o.done, 1) |
| 40 | f() |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // Reset make the once object to be initialized once again. |
| 45 | func (o *Once) Reset() { |
no outgoing calls