Optional
thenableOrResult: Resolvable<R>Optional
error: anyOptional
onCancel: ((callback: (() => void)) => void)Readonly
[toThis is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
tslint:disable-next-line:unified-signatures
Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise.
There are special semantics for .finally()
in that the final value cannot be modified from the handler.
Alias .lastly();
for compatibility with earlier ECMAScript version.
Static
PromiseCreate a new promise. The passed in function will receive functions resolve
and reject
as its arguments which can be called to seal the fate of the created promise.
If promise cancellation is enabled, passed in function will receive one more function argument onCancel
that allows to register an optional cancellation callback.
Static
versionThe version number of the library
Same as calling Promise.all(thisPromise)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Same as calling Promise.all(thisPromise)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Same as calling Promise.any(thisPromise)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Same as calling Promise.any(thisPromise)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Optional
value: ROptional
options: SpreadOptionRest
...sink: any[]Create a promise that follows this promise, but is bound to the given thisArg
value.
A bound promise will call its handlers with the bound value set to this
.
Additionally promises derived from a bound promise will also be bound promises with the same thisArg
binding as the original promise.
This is a convenience method for doing:
promise.then(function(obj){
return obj[propertyName].call(obj, arg...);
});
Rest
...args: any[]This is a catch-all exception handler, shortcut for calling .then(null, handler)
on this promise.
Any exception happening in a .then
-chain will propagate to nearest .catch
handler.
Alias .caught();
for compatibility with earlier ECMAScript version.
This extends .catch
to work more like catch-clauses in languages like Java or C#.
Instead of manually checking instanceof
or .name === "SomeError"
,
you may specify a number of error constructors which are eligible for this catch handler.
The catch handler that is first met that has eligible constructors specified, is the one that will be called.
This method also supports predicate-based filters. If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument. The return result of the predicate will be used determine whether the error handler should be called.
Alias .caught();
for compatibility with earlier ECMAScript version.
tslint:disable-next-line:unified-signatures
Convenience method for:
.catch(function() {
return value;
});
in the case where value
doesn't change its value. That means value
is bound at the time of calling .catchReturn()
No need to be specific about Error types in these overrides, since there's no handler function
tslint:disable-next-line:unified-signatures
Convenience method for:
.catch(function() {
throw reason;
});
Same limitations apply as with `.catchReturn()`.No need to be specific about Error types in these overrides, since there's no handler function
tslint:disable-next-line:unified-signatures
A meta method used to specify the disposer method that cleans up a resource when using Promise.using
.
Returns a Disposer object which encapsulates both the resource as well as the method to clean it up.
The user can pass this object to Promise.using
to get access to the resource when it becomes available,
as well as to ensure its automatically cleaned up.
The second argument passed to a disposer is the result promise of the using block, which you can inspect synchronously.
Like .then()
, but any unhandled rejection that ends up here will be thrown as an error.
Optional
onFulfilled: ((value: R) => Resolvable<U>)Optional
onRejected: ((error: any) => Resolvable<U>)Same as calling Bluebird.each(thisPromise, iterator)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Like .catch
but instead of catching all types of exceptions,
it only catches those that don't originate from thrown errors but rather from explicit rejections.
Same as calling Promise.filter(thisPromise, filterer)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Optional
options: ConcurrencyOptionPass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise.
There are special semantics for .finally()
in that the final value cannot be modified from the handler.
Alias .lastly();
for compatibility with earlier ECMAScript version.
Same as calling Bluebird.map(thisPromise, mapper)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Optional
options: ConcurrencyOptionSame as calling Bluebird.mapSeries(thisPromise, iterator)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Register a node-style callback on this promise.
When this promise is is either fulfilled or rejected, the node callback will be called back with the node.js convention where error reason is the first argument and success value is the second argument.
The error argument will be null
in case of success.
If the callback
argument is not a function, this method does not do anything.
Optional
value: ROptional
options: SpreadOptionRest
...sink: any[]Same as calling Promise.props(thisPromise)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Same as calling Promise.race(thisPromise, count)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Same as calling Promise.race(thisPromise, count)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Same as calling Promise.reduce(thisPromise, Function reducer, initialValue)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Optional
initialValue: USynchronously inspect the state of this promise
. The PromiseInspection
will represent the state of
the promise as snapshotted at the time of calling .reflect()
.
Convenience method for:
.then(function() {
return value;
});
in the case where value
doesn't change its value. That means value
is bound at the time of calling .return()
Alias .thenReturn();
for compatibility with earlier ECMAScript version.
Same as calling Promise.some(thisPromise)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Same as calling Promise.some(thisPromise)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Same as calling Promise.some(thisPromise)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Same as calling Promise.some(thisPromise)
. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
Like calling .then
, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers.
Rest
...values: Q[]Like .catch()
but rethrows the error
Optional
error: anytslint:disable-next-line:unified-signatures
Based on PromiseLike.then, but returns a Bluebird instance.
Optional
onFulfill: ((value: R) => Resolvable<U>)Optional
onReject: ((error: any) => Resolvable<U>)Optional
onfulfilled: null | ((value: R) => Resolvable<TResult1>)Optional
onrejected: null | ((reason: any) => Resolvable<TResult2>)Returns a promise that will be fulfilled with this promise's fulfillment value or rejection reason. However, if this promise is not fulfilled or rejected within ms milliseconds, the returned promise is rejected with a TimeoutError or the error as the reason.
You may specify a custom error message with the message
parameter.
Optional
message: string | ErrorStatic
allTODO enable more overloads array with promises of different types
array with values
Static
allStatic
anyLike Promise.some()
, with 1 as count
. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly.
Static
attemptStatic
bindStatic
castCast the given value
to a trusted promise.
If value
is already a trusted Promise
, it is returned as is. If value
is not a thenable, a fulfilled is: Promise returned with value
as its fulfillment value.
If value
is a thenable (Promise-like object, like those returned by jQuery's $.ajax
), returns a trusted that: Promise assimilates the state of the thenable.
Static
configConfigure long stack traces, warnings, monitoring and cancellation. Note that even though false is the default here, a development environment might be detected which automatically enables long stack traces and warnings.
Optional
asyncEnable async hooks
Optional
cancellation?: booleanEnable cancellation
Optional
longEnable long stack traces
Optional
monitoring?: booleanEnable monitoring
Optional
warnings?: boolean | { Enable warnings
Static
coroutineTODO: After https://github.com/Microsoft/TypeScript/issues/2983 is implemented, we can use the return type propagation of generators to automatically infer the return type T.
Optional
options: CoroutineOptionsTODO: After https://github.com/Microsoft/TypeScript/issues/2983 is implemented, we can use the return type propagation of generators to automatically infer the return type T.
Optional
options: CoroutineOptionsOptional
options: CoroutineOptionsOptional
options: CoroutineOptionsOptional
options: CoroutineOptionsOptional
options: CoroutineOptionsOptional
options: CoroutineOptionsOptional
options: CoroutineOptionsOptional
options: CoroutineOptionsStatic
deferCreate a promise with undecided fate and return a PromiseResolver
to control it. See resolution?: Promise(#promise-resolution).
http://bluebirdjs.com/docs/deprecated-apis.html#promise-resolution
Static
delayReturns a promise that will be resolved with value (or undefined) after given ms milliseconds. If value is a promise, the delay will start counting down when it is fulfilled and the returned promise will be fulfilled with the fulfillment value of the value promise.
Static
eachIterate over an array, or a promise of an array,
which contains promises (or a mix of promises and values) with the given iterator function with the signature (item, index, value)
where item is the resolved value of a respective promise in the input array.
Iteration happens serially. If any promise in the input array is rejected the returned promise is rejected as well.
Resolves to the original array unmodified, this method is meant to be used for side effects. If the iterator function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration.
Static
filterFilter an array, or a promise of an array,
which contains a promises (or a mix of promises and values) with the given filterer
function with the signature (item, index, arrayLength)
where item
is the resolved value of a respective promise in the input array.
If any promise in the input array is rejected the returned promise is rejected as well.
The return values from the filtered functions are coerced to booleans, with the exception of promises and thenables which are awaited for their eventual result.
*The original array is not modified.
Optional
option: ConcurrencyOptionStatic
fromOptional
result: TOptional
options: FromNodeOptionsStatic
fromReturns a promise that is resolved by a node style callback function.
Optional
result: TOptional
options: FromNodeOptionsStatic
isStatic
joinPromise.join(
Promise
Note: In 1.x and 0.x Promise.join used to be a Promise.all that took the values in as arguments instead in an array. This behavior has been deprecated but is still supported partially - when the last argument is an immediate function value the new semantics will apply
use .all instead
Rest
...values: Resolvable<R>[]Static
longCall this right after the library is loaded to enabled long stack traces.
Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have already been created. Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency.
Static
mapMap an array, or a promise of an array,
which contains a promises (or a mix of promises and values) with the given mapper
function with the signature (item, index, arrayLength)
where item
is the resolved value of a respective promise in the input array.
If any promise in the input array is rejected the returned promise is rejected as well.
If the mapper
function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well.
The original array is not modified.
Optional
options: ConcurrencyOptionStatic
mapGiven an Iterable(arrays are Iterable), or a promise of an Iterable, which produces promises (or a mix of promises and values), iterate over all the values in the Iterable into an array and iterate over the array serially, in-order.
Returns a promise for an array that contains the values returned by the iterator function in their respective positions. The iterator won't be called for an item until its previous item, and the promise returned by the iterator for that item are fulfilled. This results in a mapSeries kind of utility but it can also be used simply as a side effect iterator similar to Array#forEach.
If any promise in the input array is rejected or any promise returned by the iterator function is rejected, the result will be rejected as well.
Static
methodReturns a new function that wraps the given function fn
.
The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function.
This method is convenient when a function can sometimes return synchronously or throw synchronously.
Returns a new function that wraps the given function fn
.
The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function.
This method is convenient when a function can sometimes return synchronously or throw synchronously.
Rest
...args: any[]Static
onAdd handler
as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or console.error
in browsers.
Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections.
Add handler as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or console.error in browsers.
Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections.
Note: this hook is specific to the bluebird instance its called on, application developers should use global rejection events.
Static
promisifyReturns a function that will wrap the given nodeFunction
.
Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given node function. The node function should conform to node.js convention of accepting a callback as last argument and calling that callback with error as the first argument and success value on the second argument.
If the nodeFunction
calls its callback with multiple success values, the fulfillment value will be an array of them.
If you pass a receiver
, the nodeFunction
will be called as a method on the receiver
.
Optional
result: TOptional
options: PromisifyOptionsReturns a function that will wrap the given nodeFunction
.
Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given node function. The node function should conform to node.js convention of accepting a callback as last argument and calling that callback with error as the first argument and success value on the second argument.
If the nodeFunction
calls its callback with multiple success values, the fulfillment value will be an array of them.
If you pass a receiver
, the nodeFunction
will be called as a method on the receiver
.
Optional
result: TOptional
options: PromisifyOptionsOptional
result: TOptional
options: PromisifyOptionsOptional
result: TOptional
options: PromisifyOptionsOptional
result: TOptional
options: PromisifyOptionsOptional
result: TOptional
options: PromisifyOptionsRest
...args: any[]Optional
options: PromisifyOptionsStatic
promisifyTODO how to model promisifyAll?
Optional
options: PromisifyAllOptions<T>Static
propsmap
trusted promise for object
object
Static
raceGiven an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value.
Note If you pass empty array or a sparse array with no values, or a promise/thenable for such, it will be forever pending.
Static
reduceReduce an array, or a promise of an array,
which contains a promises (or a mix of promises and values) with the given reducer
function with the signature (total, current, index, arrayLength)
where item
is the resolved value of a respective promise in the input array.
If any promise in the input array is rejected the returned promise is rejected as well.
If the reducer function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration.
*The original array is not modified. If no initialValue
is given and the array doesn't contain at least 2 items,
the callback will not be called and undefined
is returned.
If initialValue
is given and the array doesn't have at least 1 item, initialValue
is returned.*
Optional
initialValue: UStatic
rejectStatic
resolveCreate a promise that is resolved with the given value
. If value
is a thenable or promise, the returned promise will assume its state.
Static
someInitiate a competitive race between multiple promises or values (values will become immediately fulfilled promises).
When count
amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of
the winners in order of resolution.
If too many promises are rejected so that the promise can never become fulfilled, it will be immediately rejected with an array of rejection reasons in the order they were thrown in.
The original array is not modified.
Static
tryStart the chain of promises with Promise.try
. Any synchronous exceptions will be turned into rejections on the returned promise.
Note about second argument: if it's specifically a true array, its values become respective arguments for the function call. Otherwise it is passed as is as the first argument for the function call.
Alias for attempt();
for compatibility with earlier ECMAScript version.
Static
usingIn conjunction with .disposer
, using will make sure that no matter what, the specified disposer
will be called when the promise returned by the callback passed to using has settled. The disposer is
necessary because there is no standard interface in node for disposing resources.
Create a new promise. The passed in function will receive functions
resolve
andreject
as its arguments which can be called to seal the fate of the created promise.If promise cancellation is enabled, passed in function will receive one more function argument
onCancel
that allows to register an optional cancellation callback.