Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.
Much like then, but with different behavior around unhandled rejection. If there is an unhandled rejection, either because promise is rejected and no onRejected callback was provided, or because onFulfilled or onRejected threw an error or returned a rejected promise, the resulting rejection reason is thrown as an exception in a future turn of the event loop.
This method should be used to terminate chains of promises that will not be passed elsewhere. Since exceptions thrown in then callbacks are consumed and transformed into rejections, exceptions at the end of the chain are easy to accidentally, silently ignore. By arranging for the exception to be thrown in a future turn of the event loop, so that it won't be caught, it causes an onerror event on the browser window, or an uncaughtException event on Node.js's process object.
Exceptions thrown by done will have long stack traces, if Q.longStackSupport is set to true. If Q.onerror is set, exceptions will be delivered there instead of thrown in a future turn.
The Golden Rule of done vs. then usage is: either return your promise to someone else, or if the chain ends with you, call done to terminate it.
Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object.
finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished.
Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object.
finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished.
Returns a promise to get the named property of an object. Essentially equivalent to
promise.then(function (o) { return o[propertyName]; });
Returns a "state snapshot" object, which will be in one of three forms:
Returns a promise for the result of calling the named method of an object with the given variadic arguments. The object itself is this in the function, just like a synchronous method call.
Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true.
Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.
Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false.
Returns a promise for an array of the property names of an object. Essentially equivalent to
promise.then(function (o) { return Object.keys(o); });
If callback is a function, assumes it's a Node.js-style callback, and calls it as either callback(rejectionReason) when/if promise becomes rejected, or as callback(null, fulfillmentValue) when/if promise becomes fulfilled. If callback is not a function, simply returns promise.
Returns a promise for the result of calling the named method of an object with the given array of arguments. The object itself is this in the function, just like a synchronous method call. Essentially equivalent to
promise.then(function (o) { return o[methodName].apply(o, args); });
A sugar method, equivalent to promise.then(undefined, undefined, onProgress).
Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason.
This is especially useful in conjunction with all
The then method from the Promises/A+ specification, with an additional progress handler.
The then method from the Promises/A+ specification, with an additional progress handler.
The then method from the Promises/A+ specification, with an additional progress handler.
The then method from the Promises/A+ specification, with an additional progress handler.
A sugar method, equivalent to promise.then(function () { throw reason; }).
A sugar method, equivalent to promise.then(function () { return value; }).
A sugar method, equivalent to promise.then(undefined, onRejected).