Tuan-Anh Tran

bluebird - a promise library with unmatched performance

Posted on January 17, 2015  •  1 minutes  • 110 words

The documentation of bluebird is so much better than Q - the library which I’m currently using. bluebird with nodejs is even better: it can convert an existing promise-unaware API to promise-returning API which is so awesome. Thid feature works with most popular libraries (which use error as first arg (as they all should)).

I’m sold!!

Usage

function getConnection(urlString) {
  return new Promise(function(resolve) {
    //Without new Promise, this throwing will throw an actual exception
    var params = parse(urlString);
    resolve(getAdapater(params).getConnection());
  });
}

or with promisifyAll method

var fs = require("fs");
Promise.promisifyAll(fs);
// Now you can use fs as if it was designed to use bluebird promises from the beginning

fs.readFileAsync("file.js", "utf8").then(...)
Follow me

Here's where I hang out in social media