once

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 2 Imported by: 3

Documentation

Overview

Package once provides a way to call a function exactly once (memoisation).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handle

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

func Once

func Once[T any](f func(context.Context) (T, error)) *Handle[T]

Once returns a new Handle[T] that calls f exactly once.

The returned Handle[T] is safe for concurrent use. If f returns an error, the error will be returned by Get on all subsequent calls.

func (*Handle[T]) Get

func (h *Handle[T]) Get(ctx context.Context) (T, error)

Jump to

Keyboard shortcuts

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