Creates a new deferred. This API is preferred over dojo/_base/Deferred.
Creates a new deferred, as an abstraction over (primarily)
asynchronous operations. The deferred is the private interface
that should not be returned to calling code. That's what the
promise
is for. See dojo/promise/Promise.
Parameter | Type | Description |
---|---|---|
canceler | Function |
Optional Will be invoked if the deferred is canceled. The canceler
receives the reason the deferred was canceled as its argument.
The deferred is rejected with its return value, or a new
|
See the dojo/Deferred reference documentation for more information.
Inform the deferred it may cancel its asynchronous operation.
Inform the deferred it may cancel its asynchronous operation. The deferred's (optional) canceler is invoked and the deferred will be left in a rejected state. Can affect other promises that originate with the same deferred.
Parameter | Type | Description |
---|---|---|
reason | any | A message that may be sent to the deferred's canceler, explaining why it's being canceled. |
strict | Boolean |
Optional If strict, will throw an error if the deferred has already been fulfilled and consequently cannot be canceled. |
Returns the rejection reason if the deferred was canceled normally.
Emit a progress update on the deferred.
Emit a progress update on the deferred. Progress updates can be used to communicate updates about the asynchronous operation before it has finished.
Parameter | Type | Description |
---|---|---|
update | any | The progress update. Passed to progbacks. |
strict | Boolean |
Optional If strict, will throw an error if the deferred has already been fulfilled and consequently no progress can be emitted. |
Returns the original promise for the deferred.
Reject the deferred.
Reject the deferred, putting it in an error state.
Parameter | Type | Description |
---|---|---|
error | any | The error result of the deferred. Passed to errbacks. |
strict | Boolean |
Optional If strict, will throw an error if the deferred has already been fulfilled and consequently cannot be rejected. |
Returns the original promise for the deferred.
Resolve the deferred.
Resolve the deferred, putting it in a success state.
Parameter | Type | Description |
---|---|---|
value | any | The result of the deferred. Passed to callbacks. |
strict | Boolean |
Optional If strict, will throw an error if the deferred has already been fulfilled and consequently cannot be resolved. |
Returns the original promise for the deferred.
Add new callbacks to the deferred.
Add new callbacks to the deferred. Callbacks can be added before or after the deferred is fulfilled.
Parameter | Type | Description |
---|---|---|
callback | Function |
Optional Callback to be invoked when the promise is resolved. Receives the resolution value. |
errback | Function |
Optional Callback to be invoked when the promise is rejected. Receives the rejection error. |
progback | Function |
Optional Callback to be invoked when the promise emits a progress update. Receives the progress update. |
Returns a new promise for the result of the callback(s). This can be used for chaining many asynchronous operations.