promise

package
v1.52.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package promise carries no dependencies beyond the standard library, so a package that needs only a promise does not inherit the rest of utils.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Await

func Await[T any](ctx context.Context, p *Promise[T]) (T, error)

Types

type Promise

type Promise[T any] struct {
	Result T
	Err    error
	// contains filtered or unexported fields
}

func Go

func Go[T any](f func() (T, error)) *Promise[T]

func New

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

func NewResolved

func NewResolved[T any](result T, err error) *Promise[T]

NewResolved is spelled apart from the Resolved method, which reports whether a promise has settled.

func (*Promise[T]) Done

func (p *Promise[T]) Done() <-chan struct{}

func (*Promise[T]) Resolve

func (p *Promise[T]) Resolve(result T, err error)

func (*Promise[T]) Resolved

func (p *Promise[T]) Resolved() bool

func (*Promise[T]) Then

func (p *Promise[T]) Then(f func(T, error))

Then registers f to run when p resolves, on the goroutine that calls Resolve. If p is already resolved, f runs inline on the calling goroutine.

Jump to

Keyboard shortcuts

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