promise

package
v0.30.113 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 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](
	ctx context.Context,
	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[T any](
	ctx context.Context,
	delay time.Duration,
) *Promise[T]

func Empty added in v0.30.97

func Empty() *Promise[struct{}]

func Erase added in v0.30.91

func Erase[A any](p *Promise[A]) *Promise[struct{}]

func IndirectReturn added in v0.30.91

func IndirectReturn[A, B any](p *Promise[A], val *B) *Promise[B]

func New

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

func Race

func Race[T any](
	ctx context.Context,
	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 RejectEmpty added in v0.30.98

func RejectEmpty(err error) *Promise[struct{}]

func Resolve

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

Resolve creates a Promise in the resolved state.

func Return added in v0.30.91

func Return[A, B any](p *Promise[A], val B) *Promise[B]

func Slice added in v0.30.91

func Slice[A any](p *Promise[A]) *Promise[[]A]

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 (*Promise[T]) Await

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

func (*Promise[T]) AwaitAny

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

func (*Promise[T]) Cancel added in v0.30.90

func (p *Promise[T]) Cancel()

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]) OnCancel added in v0.30.91

func (p *Promise[T]) OnCancel(fun func()) *Promise[T]

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