package
Version:
v1.0.0
Opens a new window with list of versions in this module.
Published: Aug 25, 2025
License: MIT
Opens a new window with license information.
Imports: 1
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Once
Package once provides a generic once type. It allows you to lazily initialize a variable in a concurrently safe way.
Documentation
¶
Package once provides a generic once type. It allows you to lazily initialize a variable in a concurrently safe way.
type Once[T any] struct {
}
Once is a wrapper around an initialization function, ensuring it happens only once, even in a concurrent environment.
func New[T any](f func() T) *Once[T]
New creates a new Once wrapper around an initialization function.
func (s *Once[T]) Get() T
Get returns the initialized object, creating it if necessary.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.