2022-02-10 22:06:57 +00:00
|
|
|
//go:build !solution
|
2021-03-05 11:27:37 +00:00
|
|
|
|
|
|
|
package once
|
|
|
|
|
|
|
|
// Once describes an object that will perform exactly one action.
|
|
|
|
type Once struct {
|
|
|
|
}
|
|
|
|
|
2021-03-08 19:59:18 +00:00
|
|
|
// New creates Once.
|
2021-03-05 11:27:37 +00:00
|
|
|
func New() *Once {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do calls the function f if and only if Do is being called for the
|
|
|
|
// first time for this instance of Once. In other words, given
|
|
|
|
// once := New()
|
|
|
|
// if once.Do(f) is called multiple times, only the first call will invoke f,
|
|
|
|
// even if f has a different value in each invocation. A new instance of
|
|
|
|
// Once is required for each function to execute.
|
|
|
|
//
|
|
|
|
// Do is intended for initialization that must be run exactly once.
|
|
|
|
//
|
|
|
|
// Because no call to Do returns until the one call to f returns, if f causes
|
|
|
|
// Do to be called, it will deadlock.
|
|
|
|
//
|
|
|
|
// If f panics, Do considers it to have returned; future calls of Do return
|
|
|
|
// without calling f.
|
|
|
|
//
|
|
|
|
func (o *Once) Do(f func()) {
|
|
|
|
|
|
|
|
}
|