pkg

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 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
}

Promise - wrap a runable, a function receives resolve func(T) and reject(error) callbacks. Note that only one of the those callbacks should be called in a Promise.

func All

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

All - pass a number of Promises. The return values of all Promises will be aggregated and returned when all Promises have settled.

func Any

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

Any - pass a number of Promises. If any of the passed Promises resolves, this Promise will terminate and the result of the first resolved Promise will be returned. When all passed Promises reject, this Promise will reject with all aggregated errors.

func Create

func Create[T any](runable func(resolve func(T), reject func(error))) *Promise[T]

Create - a Promise with the 'runable' that is to be executed async.

func Race

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

Race - pass a number of Promises. The Promise that settles first will be passes down, by this Promise.

func Then

func Then[T, R any](p *Promise[T], resolve func(T) R) *Promise[R]

Then - chain an existing Promise with an intermediate resolve function to allow manipulation of the original result. If the passed Promise does not resolve this chain will have no effect.

func (*Promise[T]) Await

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

Await - wait for the async 'runable' to finish execution then return the results.

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 to allow manipulation of the original error. If the passed Promise does not reject this chain will have no effect.

func (*Promise[T]) Pending added in v0.2.0

func (p *Promise[T]) Pending() bool

Pending - returns true if the promise has not settled yet. Otherwise returns false.

Jump to

Keyboard shortcuts

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