This section provides an overview of what bluebird is, and why a developer might want to use it.
It should also mention any large subjects within bluebird, and link out to the related topics. Since the Documentation for bluebird is new, you may need to create initial versions of those related topics.
Promises have state, they start as pending and can settle to:
Promise returning functions should never throw, they should return rejections instead. Throwing from a promise returning function will force you to use both a } catch {
and a .catch
. People using promisified APIs do not expect promises to throw. If you're not sure how async APIs work in JS - please see this answer first.
Promise.all(
Iterable<any> | Promise<Iterable<any>> input
) -> Promise
This method is useful for when you want to wait for more than one promise to complete.
Given 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 return a promise that is fulfilled when all the items in the array are fulfilled. The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array rejects, the returned promise is rejected with the rejection reason.
var files = []; for (var i = 0; i < 100; ++i) { files.push(fs.writeFileAsync("file-" + i + ".txt", "", "utf-8")); } Promise.all(files).then(function() { console.log("all the files were created"); });
This method is compatible with Promise.all
from native promises.