Documentation ¶
Index ¶
- func Await(p *Promise) (interface{}, error)
- type Interval
- type Promise
- func All(promises ...*Promise) *Promise
- func AllSettled(promises ...*Promise) *Promise
- func Async(executor func(resolve func(interface{}), reject func(interface{}))) *Promise
- func Each(promises ...*Promise) *Promise
- func Race(promises ...*Promise) *Promise
- func Reject(err error) *Promise
- func Resolve(resolution interface{}) *Promise
- func (promise *Promise) AsCallback(f func(interface{}, error))
- func (promise *Promise) Await() (interface{}, error)
- func (promise *Promise) CalTime() *Promise
- func (promise *Promise) Catch(rejection func(err error) interface{}) *Promise
- func (promise *Promise) Elapse() time.Duration
- func (promise *Promise) Reject(err interface{})
- func (promise *Promise) Resolve(resolution interface{})
- func (promise *Promise) Then(fulfillment func(data interface{}) interface{}) *Promise
- type Timeout
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Interval ¶
type Interval struct {
// contains filtered or unexported fields
}
func SetInterval ¶
type Promise ¶
type Promise struct {
// contains filtered or unexported fields
}
A Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future.
func All ¶
All waits for all promises to be resolved, or for any to be rejected. If the returned promise resolves, it is resolved with an aggregating array of the values from the resolved promises in the same order as defined in the iterable of multiple promises. If it rejects, it is rejected with the reason from the first promise in the iterable that was rejected.
func AllSettled ¶
AllSettled waits until all promises have settled (each may Resolve, or reject). Returns a promise that resolves after all of the given promises have either resolved or rejected, with an array of objects that each describe the outcome of each promise.
func Async ¶
func Async(executor func(resolve func(interface{}), reject func(interface{}))) *Promise
Async instantiates and returns a pointer to a new Promise.
func Race ¶
Race waits until any of the promises is resolved or rejected. If the returned promise resolves, it is resolved with the value of the first promise in the iterable that resolved. If it rejects, it is rejected with the reason from the first promise that was rejected.
func Resolve ¶
func Resolve(resolution interface{}) *Promise
Resolve returns a Promise that has been resolved with a given value.
func (*Promise) AsCallback ¶
func (*Promise) Await ¶
Await is a blocking function that waits for all callbacks to be executed. Returns value and error. Call on an already resolved Promise to get its result and error