once

package
v0.0.0-...-7aac2a2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Init

type Init struct {
	// contains filtered or unexported fields
}

Init represents the structure.

func (*Init) Do

func (l *Init) Do(f func() error) error

Do is similar to sync.Once.Do - makes one successful call to the function. ie, it invokes the function if it is not successful yet.

func (*Init) DoWithContext

func (l *Init) DoWithContext(ctx context.Context, f func(context.Context) error) error

DoWithContext is similar to Do except that it accepts a context as an argument to be passed.

type Singleton

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

Singleton contains a pointer to T that must be set once. Until the value is set all Get() calls will block.

func NewSingleton

func NewSingleton[T any]() *Singleton[T]

NewSingleton creates a new unset singleton.

func (*Singleton[T]) Get

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

Get will return the singleton value.

func (*Singleton[T]) GetNonBlocking

func (s *Singleton[T]) GetNonBlocking() *T

GetNonBlocking will return the singleton value or nil if not set yet.

func (*Singleton[T]) IsSet

func (s *Singleton[T]) IsSet() bool

IsSet will return whether the singleton has been set.

func (*Singleton[T]) Set

func (s *Singleton[T]) Set(v *T)

Set the value and unblock all Get requests. This may only be called once, a second call will panic.

Jump to

Keyboard shortcuts

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