-
Notifications
You must be signed in to change notification settings - Fork 1
async.Deferred
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.
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
.
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
.
deferred.progress(value);
Executes progress callbacks throughout the dependency chain, passing value
— which must not be a promise — to every one of them.
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
.
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;
};
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;
};
An error constructor, which is used by default to construct cancellation reasons. It is exposed so user can do an instanceof
check.
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.
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 asDeferred.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.