promise

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Promise

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

func All

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

All resolves when all of the promises have resolved, reject immediately upon any of the input promises rejecting.

func Any

func Any[T any](promises []*Promise[T]) *Promise[T]

Any resolves as soon as any of the input's Promises resolve, with the value of the resolved Promise. Any rejects if all of the given Promises are rejected with a combination of all errors.

func Catch

func Catch[T any](promise *Promise[T], rejection func(err error) error) *Promise[T]

Catch allows to chain promises.

func New

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

New create a new promise instance.

func Race

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

Race will settle the first fullfiled promise among muti promises.

func Reject

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

Reject returns a Promise that has been rejected with a given error.

func Resolve

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

Resolve returns a Promise that has been resolved with a given value.

func Then

func Then[T1, T2 any](promise *Promise[T1], resolve1 func(value T1) T2) *Promise[T2]

Then allows chain calls to other promise methods.

func (*Promise[T]) Await

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

Await blocks until the 'runable' to finish execution.

func (*Promise[T]) Catch

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

Catch chain an existing promise with an intermediate reject function.

func (*Promise[T]) Then

func (p *Promise[T]) Then(resolve func(value T) T) *Promise[T]

Then allows chain calls to other promise methods.

Jump to

Keyboard shortcuts

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