dojo/promise/Promise (version 1.10)

Summary

The public interface to a deferred.

The public interface to a deferred. All promises in Dojo are instances of this class.

Usage

Promise();

See the dojo/promise/Promise reference documentation for more information.

Method Summary

  • always(callbackOrErrback) Add a callback to be invoked when the promise is resolved or rejected.
  • cancel(reason,strict) Inform the deferred it may cancel its asynchronous operation.
  • isCanceled() Checks whether the promise has been canceled.
  • isFulfilled() Checks whether the promise has been resolved or rejected.
  • isRejected() Checks whether the promise has been rejected.
  • isResolved() Checks whether the promise has been resolved.
  • otherwise(errback) Add new errbacks to the promise.
  • then(callback,errback,progback) Add new callbacks to the promise.
  • toString()
  • trace() Trace the promise.
  • traceRejected() Trace rejection of the promise.

Methods

always(callbackOrErrback)

Add a callback to be invoked when the promise is resolved or rejected.

Parameter Type Description
callbackOrErrback Function
Optional

A function that is used both as a callback and errback.

Returns:dojo/promise/Promise | undefined

Returns a new promise for the result of the callback/errback.

cancel(reason,strict)

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()

Checks whether the promise has been canceled.

Returns:Boolean
isFulfilled()

Checks whether the promise has been resolved or rejected.

Returns:Boolean
isRejected()

Checks whether the promise has been rejected.

Returns:Boolean
isResolved()

Checks whether the promise has been resolved.

Returns:Boolean
otherwise(errback)

Add new errbacks to the promise.

Parameter Type Description
errback Function
Optional

Callback to be invoked when the promise is rejected.

Returns:dojo/promise/Promise | undefined

Returns a new promise for the result of the errback.

then(callback,errback,progback)

Add new callbacks to the promise.

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.

toString()
Returns:string

Returns [object Promise].

trace()
Defined by dojo/promise/tracer

Trace the promise.

Tracing allows you to transparently log progress, resolution and rejection of promises, without affecting the promise itself. Any arguments passed to trace() are emitted in trace events. See dojo/promise/tracer on how to handle traces.

The promise instance trace() is called on.

traceRejected()
Defined by dojo/promise/tracer

Trace rejection of the promise.

Tracing allows you to transparently log progress, resolution and rejection of promises, without affecting the promise itself. Any arguments passed to trace() are emitted in trace events. See dojo/promise/tracer on how to handle traces.

The promise instance traceRejected() is called on.

Error in the documentation? Can’t find what you are looking for? Let us know!