dojo/Deferred

Summary

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.

Usage

Deferred(canceler);
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 dojo/errors/CancelError instance.

See the dojo/Deferred reference documentation for more information.

Properties

promise

Defined by: dojo/Deferred

Methods

cancel(reason,strict)

Defined by dojo/Deferred

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: any

Returns the rejection reason if the deferred was canceled normally.

isCanceled()

Defined by dojo/Deferred

Checks whether the deferred has been canceled.

Returns: Boolean

isFulfilled()

Defined by dojo/Deferred

Checks whether the deferred has been resolved or rejected.

Returns: Boolean

isRejected()

Defined by dojo/Deferred

Checks whether the deferred has been rejected.

Returns: Boolean

isResolved()

Defined by dojo/Deferred

Checks whether the deferred has been resolved.

Returns: Boolean

progress(update,strict)

Defined by dojo/Deferred

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: dojo/promise/Promise

Returns the original promise for the deferred.

reject(error,strict)

Defined by dojo/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: dojo/promise/Promise | instance

Returns the original promise for the deferred.

resolve(value,strict)

Defined by dojo/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: dojo/promise/Promise

Returns the original promise for the deferred.

then(callback,errback,progback)

Defined by dojo/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: dojo/promise/Promise

Returns a new promise for the result of the callback(s). This can be used for chaining many asynchronous operations.

toString()

Defined by dojo/Deferred

Returns: String

Returns [object Deferred].

© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/Deferred.html