cheatsheets/bluebird.md

926 B

title layout
bluebird.js default

See promise.

Consuming promises

promise
  .then(okFn, errFn)
  .spread(okFn, errFn) #*
  .catch(errFn)
  .catch(TypeError, errFn) #*
  .finally(fn) #*
  .map(function (e) { ... })
  .each(function (e) { ... });

Handling simultaneous promises

Promise.any(promises)     // succeeds if one succeeds first
  .then(...)

or Objects

Promise.props({
  photos: get('photos'),
  posts: get('posts')
})
.then(function (res) {
  res.photos
  res.posts
})

Consuming arrays

getFiles()

Chain of promises

Promise.try(function () {
  if (err) throw new Error("boo");
  return result;
});

### Working with node-style functions

```js
var readFile = Promise.promisify(fs.readFile);
var fs = Promise.promisifyAll(require('fs'));

References