future

package
v0.36.4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

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 struct that holds a value of type T, a slice of callbacks to be called when the value is set, a boolean to track if the callbacks have been called, and a mutex for thread safety.

func New

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

New returns a new Future.

func (*Future[T]) Complete

func (f *Future[T]) Complete(value T) *Future[T]

Complete sets the value and calls the registered callbacks if they haven't been called yet.

func (*Future[T]) ThenAccept

func (f *Future[T]) ThenAccept(callback func(T))

ThenAccept registers a callback to be called when the Future is completed.

func (*Future[T]) ThenAcceptParallel

func (f *Future[T]) ThenAcceptParallel(callback func(T))

ThenAcceptParallel registers a callback to be called in a separate goroutine when the Future is completed.

Jump to

Keyboard shortcuts

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