Documentation ¶
Overview ¶
Package lazy provides types for lazily initialized values.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GFunc ¶
func GFunc[T any](fill func() T) func() T
GFunc wraps a function to make it lazy.
The returned function calls fill the first time it's called, and returns fill's result on every subsequent call.
The returned function is not safe for concurrent use.
func GFuncErr ¶
SyncFuncErr wraps a function to make it lazy.
The returned function calls fill the first time it's called, and returns fill's results on every subsequent call.
The returned function is not safe for concurrent use.
func SyncFunc ¶
func SyncFunc[T any](fill func() T) func() T
SyncFunc wraps a function to make it lazy.
The returned function calls fill the first time it's called, and returns fill's result on every subsequent call.
The returned function is safe for concurrent use.
func SyncFuncErr ¶
SyncFuncErr wraps a function to make it lazy.
The returned function calls fill the first time it's called, and returns fill's results on every subsequent call.
The returned function is safe for concurrent use.
Types ¶
type GValue ¶
type GValue[T any] struct { V T // contains filtered or unexported fields }
GValue is a lazily computed value.
Use either Get or GetErr, depending on whether your fill function returns an error.
Recursive use of a GValue from its own fill function will panic.
GValue is not safe for concurrent use. (Mnemonic: G is for one Goroutine, which isn't strictly true if you provide your own synchronization between goroutines, but in practice most of our callers have been using it within a single goroutine.)
func (*GValue[T]) Get ¶
func (z *GValue[T]) Get(fill func() T) T
Get returns z's value, calling fill to compute it if necessary. f is called at most once.
func (*GValue[T]) GetErr ¶
GetErr returns z's value, calling fill to compute it if necessary. f is called at most once, and z remembers both of fill's outputs.
type SyncValue ¶
type SyncValue[T any] struct { // contains filtered or unexported fields }
SyncValue is a lazily computed value.
Use either Get or GetErr, depending on whether your fill function returns an error.
Recursive use of a SyncValue from its own fill function will deadlock.
SyncValue is safe for concurrent use.
func (*SyncValue[T]) Get ¶
func (z *SyncValue[T]) Get(fill func() T) T
Get returns z's value, calling fill to compute it if necessary. f is called at most once.
func (*SyncValue[T]) GetErr ¶
GetErr returns z's value, calling fill to compute it if necessary. f is called at most once, and z remembers both of fill's outputs.