promise

package
v3.116.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompletionSource

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

CompletionSource is a source for a promise that can be resolved or rejected. It is safe to call Resolve or Reject multiple times concurrently, the first will apply and all others will return that they couldn't set the promise.

func (*CompletionSource[T]) Fulfill

func (ps *CompletionSource[T]) Fulfill(value T) bool

func (*CompletionSource[T]) MustFulfill

func (ps *CompletionSource[T]) MustFulfill(value T)

func (*CompletionSource[T]) MustReject

func (ps *CompletionSource[T]) MustReject(err error)

func (*CompletionSource[T]) Promise

func (ps *CompletionSource[T]) Promise() *Promise[T]

func (*CompletionSource[T]) Reject

func (ps *CompletionSource[T]) Reject(err error) bool

type Promise

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

Promise is a promise that can be resolved with a value of type T or rejected with an error. It is safe to call Result on it multiple times from multiple goroutines. This is much more permissive than channels.

func Run

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

Run runs the given function in a goroutine and returns a promise that will be resolved with the result of the function.

func (*Promise[T]) Result

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

Result waits for the promise to be resolved and returns the result.

func (*Promise[T]) TryResult added in v3.95.0

func (p *Promise[T]) TryResult() (T, error, bool)

TryResult returns the result and true if the promise has been resolved, otherwise it returns false.

Jump to

Keyboard shortcuts

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