async-straight

1.0.3 • Public • Published

async-straight

NPM

A light weight module to run asynchronous tasks in series, inspired from async.series

Installation

npm install async-straight

API

var straight = require('async-straight')

straight(tasks, [callback])

It executes each function in tasks in series and after their execution calls the optional callback(if supplied).

Arguments

  • tasks - An array or object containing functions to run, each function is passed a cb(err, result) it must call on completion with an error err (which can be null) and an optional result value.
  • callback(err, results) - An optional callback to run once all the functions have completed. This function gets a results array (or object) containing all the result arguments passed to the task callbacks.

Example

straight([
   function(cb) {
      setTimeout(function() {
         cb(null, "hello");
      }, 1000);
   },
   function(cb) {
      setTimeout(function() {
         cb(null, "world");
      }, 2000);
   }
], function(err, result) {
   // result is equal to ["hello","world"]
});
 
// an example using an object instead of an array
straight({
    one: function(cb){
        setTimeout(function(){
            cb(null, "ping");
        }, 200);
    },
    two: function(callback){
        setTimeout(function(){
            cb(null, "pong");
        }, 100);
    }
},
function(err, results) {
    // results is now equal to: {one: "ping", two: "pong"}
});

Tests

npm run test

Author

Tabish Rizvi (sayyidtabish@gmail.com)

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i async-straight

Weekly Downloads

3

Version

1.0.3

License

MIT

Last publish

Collaborators

  • sayyidtabish