Skip to content
Eugene Lazutkin edited this page Mar 3, 2016 · 2 revisions

Constructor

var deferred = new Deferred(function (reason) { ... });

Constructs a new, unresolved, Deferred object. The optional argument can be used to pass in the canceller function which will only be called in the event the Deferred is cancelled and will have a chance of prematurely terminating the asynchronous process that was supposed to resolve it in the first place.

resolve()

deferred.resolve(valueOrPromise, catchUnhandled);

Resolves the deferred to a non-promise value or another promise. Optional argument catchUnhandled is used the same way as in Promise.cancel.

reject()

deferred.reject(valueOrPromise, catchUnhandled);

Rejects the deferred with a non-promise value or with another promise. Optional argument catchUnhandled is used the same way as in Promise.cancel.

progress()

deferred.progress(value);

Executes progress callbacks throughout the dependency chain, passing value — which must not be a promise — to every one of them.

Deferred.detectUncaught

A Boolean property. If it is true, any promise rejection will check if there are subscribers to such event to help debug so-called "silent failures". Otherwise, no special check is done. Default: false.

Deferred.resolve()

var promise = Deferred.resolve(value);

Produces a resolved promise. Its meta-definition:

Deferred.resolve = function (value) {
  var deferred = new Deferred();
  deferred.resolve(value, true);
  return deferred;
};

Deferred.reject()

var promise = Deferred.reject(value);

Produces a rejected promise. Its meta-definition:

Deferred.reject = function (value) {
  var deferred = new Deferred();
  deferred.reject(value, true);
  return deferred;
};

Deferred.CancelError

An error constructor, which is used by default to construct cancellation reasons. It is exposed so user can do an instanceof check.

Deferred.Promise

A promise constructor. It cannot be used directly. It is exposed so user can do an instanceof check. For more information on instances produced by this constructor, see Deferred.Promise.

Deferred.Wrapper

An constructor that emulates the standard Promise constructor. Following operations and properties are defined:

  • Deferred.Wrapper() — a constructor. See Promise for more details.
  • Deferred.Wrapper.resolve() — produces a resolved promise. See Promise.resolve() for more details.
  • Deferred.Wrapper.reject() — produces a rejected promise. See Promise.reject() for more details.
  • Deferred.Wrapper.Promise — the same as Deferred.Promise described above.

Note that the wrapper do not come with all() and race() functions. They are added by Deferred-ext module, which should be used, if such functionality is required.