NOTE

sync.Once

Exactly-once process-local initialization and its concurrency semantics.

GoCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

sync.Once ensures that one supplied function is executed at most once for that Once instance, while concurrent callers wait for the single invocation to finish.

It is useful for lazy initialization and one-time registration. If the function panics, that invocation is still considered the one execution, so design initialization/retry behavior intentionally. Do not copy a Once after first use.

Loading helpful count