promise

package
v1.54.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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