promise

package
v0.30.45 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inspect

func Inspect(typ reflect.Type) (reflect.Type, bool)

Types

type CanceledError added in v0.26.0

type CanceledError struct {
	// contains filtered or unexported fields
}

func (CanceledError) Cause added in v0.28.0

func (e CanceledError) Cause() error

func (CanceledError) Error added in v0.26.0

func (e CanceledError) Error() string

func (CanceledError) Unwrap added in v0.26.0

func (e CanceledError) Unwrap() error

type Deferred

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

Deferred represents a computation that fulfills a Promise.

func Defer

func Defer[T any]() Deferred[T]

Defer creates a Deferred computation.

func DeferWithContext added in v0.28.0

func DeferWithContext[T any](ctx context.Context) Deferred[T]

DeferWithContext creates a Deferred computation in a context.

func (Deferred[T]) Promise

func (d Deferred[T]) Promise() *Promise[T]

func (Deferred[T]) Reject

func (d Deferred[T]) Reject(err error)

func (Deferred[T]) Resolve

func (d Deferred[T]) Resolve(resolution T)

type Promise

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

Promise represents the eventual completion (or failure) of an asynchronous operation and its resulting value

func All

func All[T any](
	promises ...*Promise[T],
) *Promise[[]T]

All resolves when all promises have resolved, or rejects immediately upon any of the promises rejecting

func Catch

func Catch[T any](p *Promise[T], reject func(err error) error) *Promise[T]

func Coerce

func Coerce[T any](
	promise Reflect,
) *Promise[T]

func Delay

func Delay(delay time.Duration) *Promise[any]

func New

func New[T any](executor func(resolve func(T), reject func(error))) *Promise[T]

func Race

func Race[T any](
	promises ...*Promise[T],
) *Promise[T]

Race resolves or rejects as soon as any one of the promises resolves or rejects

func Reject

func Reject[T any](err error) *Promise[T]

Reject creates a Promise in the rejected state.

func Resolve

func Resolve[T any](value T) *Promise[T]

Resolve creates a Promise in the resolved state.

func Then

func Then[A, B any](p *Promise[A], resolve func(A) B) *Promise[B]

func Unwrap

func Unwrap[T any](
	promise *Promise[*Promise[T]],
) *Promise[T]

func WithContext added in v0.28.0

func WithContext[T any](executor func(resolve func(T), reject func(error)), ctx context.Context) *Promise[T]

func (*Promise[T]) Await

func (p *Promise[T]) Await() (T, error)

func (*Promise[T]) AwaitAny

func (p *Promise[T]) AwaitAny() (any, error)

func (*Promise[T]) Catch

func (p *Promise[T]) Catch(
	rej func(err error) error,
) *Promise[any]

func (*Promise[T]) Context added in v0.30.20

func (p *Promise[T]) Context() context.Context

func (*Promise[T]) Then

func (p *Promise[T]) Then(
	res func(data any) any,
) *Promise[any]

func (*Promise[T]) UnderlyingType

func (p *Promise[T]) UnderlyingType() reflect.Type

type Reflect

type Reflect interface {
	Context() context.Context
	UnderlyingType() reflect.Type
	Then(resolve func(data any) any) *Promise[any]
	Catch(reject func(err error) error) *Promise[any]
	AwaitAny() (any, error)
}

func CoerceType

func CoerceType(
	typ reflect.Type,
	promise Reflect,
) Reflect

func Lift

func Lift(typ reflect.Type, result any) Reflect

Jump to

Keyboard shortcuts

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