future

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package future provides a value that one goroutine sets once and others wait for.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Future

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

Future is a value that is set at most once. Once set it never changes, so waiters may keep using it without a lock.

func New

func New[T any]() *Future[T]

New returns a Future that is not set yet.

func (*Future[T]) Get

func (f *Future[T]) Get() (value T, ready bool)

Get returns the value without waiting, or false if it is not set yet.

func (*Future[T]) Set

func (f *Future[T]) Set(value T) (stored bool)

Set stores value and wakes every waiter. It reports false, keeping the first value, if the Future is already set.

func (*Future[T]) Wait

func (f *Future[T]) Wait(ctx context.Context) (T, error)

Wait blocks until the value is set or ctx is done.

Jump to

Keyboard shortcuts

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