Javascript Notes - newgeekorder/TechWiki GitHub Wiki
Back to Home
- JSON Activity Streams
- Bluebird promises is a full featured promise library. This adds a catch exception options to handle errors when async events don't return expected values.
Unhandled rejections/exceptions don't really have a good agreed-on asynchronous correspondence. The problem is that it is impossible to predict the future and know if a rejected promise will eventually be handled.
Existing api's are convered by means of Promisification which means converting an existing promise-unaware API to a promise-returning API.
The usual way to use promises in node is to promisifyAll some API and start exclusively calling promise returning versions of the APIs methods. E.g.
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(...)
- Similar to gpars asyncjs or Async provides around 20 functions that include the usual 'functional' suspects (map, reduce, filter, each…) as well as some common patterns for asynchronous control flow (parallel, series, waterfall…). All these functions assume you follow the Node.js convention of providing a single callback as the last argument of your async function.
async.parallel([
function(){ ... },
function(){ ... }
], callback);
async.series([
function(){ ... },
function(){ ... }
]);