Documentation
¶
Index ¶
- type Promise
- func All[T any](promises ...*Promise[T]) *Promise[[]T]
- func Any[T any](promises ...*Promise[T]) *Promise[T]
- func Create[T any](runable func(resolve func(T), reject func(error))) *Promise[T]
- func Race[T any](promises ...*Promise[T]) *Promise[T]
- func Then[T, R any](p *Promise[T], resolve func(T) R) *Promise[R]
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 ¶
All - pass a number of Promises. The return values of all Promises will be aggregated and returned when all Promises have settled.
func Any ¶
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 Race ¶
Race - pass a number of Promises. The Promise that settles first will be passes down, by this Promise.
func Then ¶
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 ¶
Await - wait for the async 'runable' to finish execution then return the results.