once

package
v0.0.0-...-1c0f521 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

once contains helpers for constructing type-safe, concurrency-safe values that are only ever initialized once, and can potentially return an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, V any] interface {
	// Set initializes the key K at most one time, and returns the result.
	Set(K, func() (*V, error)) (*V, error)
	// Get returns the initialization result associated with the key K.
	// If K has not yet been initialized, the result will be (<nil>, <nil>).
	Get(K) (*V, error)
}

Map is a type-safe and concurrency-safe implementation of a map where each entry is initialized a single time.

func NewMap

func NewMap[K comparable, V any]() Map[K, V]

NewMap returns a Map, a type-safe and concurrency-safe implementation of a map where each entry is initialized a single time.

type Var

type Var[T any] interface {
	// Set initializes the var at most one time, and returns the result.
	// If K has not yet been initialized, the result will be (<nil>, <nil>).
	Set(func() (*T, error)) (*T, error)
	// Get returns the initialized result. If the var has not yet been
	// initialized, the result will be (<nil>, <nil>)
	Get() (*T, error)
}

Var is a type-safe and concurrency-safe wrapper for a value that is initialized a single time.

func NewVar

func NewVar[T any]() Var[T]

NewVar returns a Var, a type-safe and concurrency-safe wrapper for a value that is initialized a single time.

Jump to

Keyboard shortcuts

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