Documentation ¶
Index ¶
- type Promise
- func All[T any](promises ...*Promise[T]) *Promise[[]T]
- func Any[T any](promises ...*Promise[T]) *Promise[T]
- func Catch[T any](promise *Promise[T], rejection func(err error) error) *Promise[T]
- func New[T any](executor func(resolve func(T), reject func(error))) *Promise[T]
- func Race[T any](promises ...*Promise[T]) *Promise[T]
- func Reject[T any](err error) *Promise[T]
- func Resolve[T any](resolution T) *Promise[T]
- func Then[A, B any](promise *Promise[A], resolveA func(data A) B) *Promise[B]
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 represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
func All ¶
All resolves when all of the input's promises have resolved. All rejects immediately upon any of the input promises rejecting. All returns nil if the input is empty.
func Any ¶
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. Any returns nil if the input is empty.
func Catch ¶
Catch allows to chain promises. Use it to add an error handler to the rejected promise.
func Race ¶
Race resolves or rejects as soon as one of the input's Promises resolve or reject, with the value or error of that Promise. Race returns nil if the input is empty.