risposta

functions from async.js implemented using promises

npm install risposta
6 downloads in the last week
7 downloads in the last month

risposta

Functions from caolan/async implemented using promises.

Internally risposta uses the popular Promise implementation Q and the new faster Promise library bluebird.

The inital code for risposta is based off this gist by @wavdad. risposta is feature complete with async.js. For example the implemenation of async.series & async.parallel by @wavdad does not support the ability to pass in a object containing task functions as properties. This meas that you can easily replace async with risposta.

The tests for risposta is actually the nodeunit tests from async converted to Mocha and promisified.

Usage

Install it via;

npm install risposta
/** This will initilize the bluebird implementation of async
* you can also call .q() to initilize the implementation of
* async using Q
*/

var async = require('risposta').bluebird();

async.series

async.series([
  function(callback){
    setTimeout(function(){
      callback(null, 2);
    }, 100);
  },

  function(callback){
    setTimeout(function(){
      callback(null, 'a', 'b');
    }, 50)
  },

  function(callback){
    setTimeout(function(){
      callback(null, 3);
    }, 110)
  }
]).then(function(results){
  console.log(results); 
  // result is [ 2, [ 'a', 'b' ], 3 ] ] ]
});

Most of the examples in the README.md of async is supported by risposta. Just keep in mind that there is no optional callback you always get a promise.

For example, the example for async.times is done like so;

// Pretend this is some complicated async factory
var createUser = function(id, callback) {
  callback(null, {
    id: 'user' + id
  })
}
// generate 5 users
async.times(5, function(n, next){
  createUser(n, function(err, user) {
    next(err, user)
  })
}).then(function(users) {
  // we should now have 5 users
});

risposta : Italian - [Noun] answer, reply, response

npm loves you