
The sync package is strongly tied to the runtime, so it's easier to implement a new one. Besides, it's pretty big so it's better to replace it.
16 строки
168 Б
Go
16 строки
168 Б
Go
package sync
|
|
|
|
type Once struct {
|
|
done bool
|
|
m Mutex
|
|
}
|
|
|
|
func (o *Once) Do(f func()) {
|
|
o.m.Lock()
|
|
defer o.m.Unlock()
|
|
if o.done {
|
|
return
|
|
}
|
|
o.done = true
|
|
f()
|
|
}
|