once source pure
Package once provides utilities for one-time execution patterns. It extends the concept of sync.Once with error handl...
Package once provides utilities for one-time execution patterns. It extends the concept of sync.Once with error handling and panic options.
1
1
1
type Once
structOnce represents a one-time execution guard
Methods on Once
func Do
method on OnceDo executes fn only once and returns nil on subsequent calls
func DoErr
method on OnceDoErr executes fn only once and returns the same error on subsequent calls
func DoOrPanic
method on OnceDoOrPanic executes fn only once and panics on subsequent calls
func DoValue
method on OnceDoValue executes fn only once and returns its value, subsequent calls return the cached value
func DoValueErr
method on OnceDoValueErr executes fn only once and returns its value and error Subsequent calls return the cached value and error
func Error
method on OnceError returns the error from the last execution if any
func IsDone
method on OnceIsDone returns whether the Once has been executed
func Reset
method on OnceReset resets the Once instance to its initial state This is mainly useful for testing purposes
func Value
method on OnceValue returns the stored value and an error if not executed yet
1
- errors stdlib