The Deferred type provides a concrete implementation of the
Promises/A+ specification that represents an operation that completes at some point in the future, optionally producing a result. A
Deferred is engineered to be instantiated and later fulfilled or rejected, exposing a
Promise whose handlers / callbacks are invoked appropriately.
Constructs a new instance of a Deferred that may be rejected or fulfilled.
Fulfills the instance, accepting an optional result. When invoked, all
onFulfilled functions attached via the then method will be invoked at the earliest opportunity after this method completes. Each
onFulfilled method will be provided the
result value specified.
- result (optional)
- The optional value produced or returned by the instance.
This method returns no value.
Obtains the current state of the Deferred instance.
The current state of the instance, where the possible values are defined by the
Obtains the Promise representation of this instance.
The Promise representation of this instance. This exposes only the
then method of the
Deferred, providing a safe data structure that can be passed to other methods without allowing modification of the underlying
Rejects the instance, accepting an optional reason. When invoked, all
onRejected functions attached via the then method will be invoked at the earliest opportunity after this method completes. Each
onRejected method will be provided the
reason value specified.
- reason (optional)
- The optional reason that the instance was rejected.
This method returns no value.
Registers methods to be invoked when the current instance is either fulfilled or rejected, returning a new
Promise that represents the return value (if any) of the invoked method.
- onFulfilled (optional)
- A method that is called after the promise is fulfilled. The fulfillment value of the promise (if present) is provided to this method as the first parameter when it is invoked. This method is invoked either one time (if the promise
is fulfilled) or not at all (if the promise is rejected). If this parameter is not a function, it is ignored.
- onRejected (optional)
- A method that is called after the promise is rejected. The rejection reason of the promise (if present) is provided to this method as the first parameter when it is invoked. This method is invoked either one time (if the promise
is rejected) or not at all (if the promise is fulfilled). If this parameter is not a function, it is ignored.
Promise that is fulfilled or rejected after onFulfilled or
onRejected has been invoked as a result of the completion of the original
Promise (i.e. a continuation). If both onFulfilled and
onRejected are ignored (i.e. not functions), this method returns the original
Promise instance, not a new one.
The fulfillment value or rejection reason (if any) of the new promise is the return value produced by either
onRejected, whichever is invoked. If the return value of
onFulfilled or onRejected is a
Promise returned by the then method assumes the state of this inner
Promise. See the
Promises/A+ specification or the examples for more information.
A numeric value indicating the state of a Deferred. These states are reflected by the
Promises/A+ specification. Possible values are:
- Awating completion (neither rejected nor fulfilled).
- Completed successfully.
- Completed erroneously.