lazy

package
v2.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2022 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lazy

type Lazy[T any] struct {
	// contains filtered or unexported fields
}

Lazy for lazy init a value. The value is computed only after Get method is called, and can only compute successfully once. If compute value panics, value will be computed again next time.

func Of

func Of[T any](compute func() T) *Lazy[T]

Of create a new Lazy instance

func (*Lazy[T]) Get

func (l *Lazy[T]) Get() T

Get return the lazy value. If value is not present yet, compute it. If value is already computing by another goroutine, wait for computing to finished. If panics while computing the value, this method panics

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL