once

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: MIT Imports: 1 Imported by: 0

README

Once

Package once provides a generic once type. It allows you to lazily initialize a variable in a concurrently safe way.

Documentation

Overview

Package once provides a generic once type. It allows you to lazily initialize a variable in a concurrently safe way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Once

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

Once is a wrapper around an initialization function, ensuring it happens only once, even in a concurrent environment.

func New

func New[T any](f func() T) *Once[T]

New creates a new Once wrapper around an initialization function.

func (*Once[T]) Get

func (s *Once[T]) Get() T

Get returns the initialized object, creating it if necessary.

Jump to

Keyboard shortcuts

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