Socket
Socket
Sign inDemoInstall

neo-async

Package Overview
Dependencies
0
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    neo-async

Neo-Async is compatible with Async.js, it is faster and has more feature.


Version published
Weekly downloads
25M
increased by0.21%
Maintainers
1
Created
Weekly downloads
 

Package description

What is neo-async?

The neo-async package is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. It is similar to the async package but with some performance improvements.

What are neo-async's main functionalities?

Control Flow

Execute a series of functions in sequential order. Each function is passed a callback it must call on completion.

async.series([
  function(callback) {
    // do some stuff ...
    callback(null, 'one');
  },
  function(callback) {
    // do some more stuff ...
    callback(null, 'two');
  }
],
function(err, results) {
  // results is now equal to ['one', 'two']
});

Collections

Apply a function to each item in a collection and collect the results.

async.map(['file1','file2','file3'], fs.stat, function(err, results) {
  // results is now an array of stats for each file
});

Utilities

Call a function a certain number of times and collect the results.

async.times(5, function(n, next) {
  createUser(n, function(err, user) {
    next(err, user);
  });
}, function(err, users) {
  // we should now have 5 users
});

Other packages similar to neo-async

Readme

Source

Neo-Async

Build Status Coverage Status

Neo-Async

nodei

Neo-Async is compatible with Async.js, it is faster and has more feature. Async is a utilty module which provides staright-forward.


Installation

In a browser

<script src="async.min.js"></script>

In an AMD loader

require(['async.min'], function(async) {});

Node.js

standard
$ npm install neo-async
var async = require('neo-async');
replacement
$ npm install neo-async
$ ln -s ./node_modules/neo-async ./node_modules/async
var async = require('async');

Feature

Collections

Control Flow

  • async.series
  • async.parallel [Limit]
  • async.waterfall
  • async.whilst
  • async.doWhilst
  • async.until
  • async.doUntil
  • async.forever
  • async.seq
  • async.applyEach [Series]
  • async.queue
  • async.priorityQueue
  • async.cargo
  • async.auto
  • async.retry
  • async.iterator
  • async.nextTick
  • async.setImmediate
  • async.times [Series, Limit]

Utils

  • async.memoize
  • async.unmemoize
  • async.log
  • async.dir
  • async.noConflict

### concat(collection, iterator, callback, thisArg)

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. iterator(item, callback) (Function): The function called per iteration.
  3. callback(err) (Function): The function called at the end.
  4. thisArg (*): The this binding of iterator.
var order = [];
var collection = [1, 3, 2];
var iterator = function(num, done) {
  setTimeout(function() {
    order.push(num);
    done(null, num);
  }, num * 10);
};
async.each(collection, iterator, function(err, res) {
  assert.deepEqual(res, [1, 2, 3]);
  assert.deepEqual(order, [1, 2, 3]);
});


### each(collection, iterator, callback, thisArg) Applies the function iterator to each item in collection, in parallel.

Aliases

async.forEach

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. iterator(item, callback) (Function): The function called per iteration.
  3. callback(err) (Function): The function called at the end.
  4. thisArg (*): The this binding of iterator.
var order = [];
var collection = [1, 3, 2];
var iterator = function(num, done) {
  setTimeout(function() {
    order.push(num);
    done();
  }, num * 10);
};
async.each(collection, iterator, function(err) {
  assert.deepEqual(order, [1, 2, 3]);
});

### eachSeries(collection, iterator, callback, thisArg) The same as each, in series.

Aliases

async.forEachSeries

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. iterator(item, callback) (Function): The function called per iteration.
  3. callback(err) (Function): The function called at the end.
  4. thisArg (*): The this binding of iterator.
var order = [];
var collection = [1, 3, 2];
var iterator = function(num, done) {
  setTimeout(function() {
    order.push(num);
    done();
  }, num * 10);
};
async.eachSeries(collection, iterator, function(err) {
  assert.deepEqual(order, [1, 3, 2]);
});

### eachLimit(collection, limit, iterator, callback, thisArg) The same as each, in limited parallel.

Aliases

async.forEachLimit

Arguments

  1. collection (Array|Object): The collection to iterate over.
  2. limit (Number): The maximum number of iterators to run at any time.
  3. iterator(item, callback) (Function): The function called per iteration.
  4. callback(err) (Function): The function called at the end.
  5. thisArg (*): The this binding of iterator.
var order = [];
var collection = [1, 3, 2];
var iterator = function(num, done) {
  setTimeout(function() {
    order.push(num);
    done();
  }, num * 10);
};
async.eachLimit(collection, 2, iterator, function(err) {
  assert.deepEqual(order, [1, 3, 2]);
});

### multiEach (collection, tasks, callback) This function provides asynchronous and straight-forward to deep nested each functions, in parallel.

Arguments

  1. collection (Array|Object): The collection to iterate over to tasks.
  2. tasks (Function[]): The function called in task order.
  3. callback(err) (Function): The function called at the end.

synchronous

vvar order = [];
var array = [1, 2, 3];
var tasks = [
  function(num, index, callback) {
    order.push(num);
    callback(null, array);
  },
  function(num, index, callback) {
    order.push(num);
    callback(null, array);
  },
  function(num, index, callback) {
    order.push(num);
    callback(null, array);
  },
  function(num, index, callback) {
    order.push(num);
    callback();
  }
];

// get same result
var _order = [];
array.forEach(function(num) {
  _order.push(num);
  array.forEach(function(num) {
    _order.push(num);
    array.forEach(function(num) {
      _order.push(num);
      array.forEach(function(num) {
        _order.push(num);
      });
    });
  });
});

async.multiEach(array, tasks, function(err) {
  assert.deepEqual(order, _order);
});

asynchronous

var order = [];
var array = [1, 2, 3];
var collection = {
  a: [array, array],
  b: {
    c: array,
    d: array
  }
};
var delay = [25, 10];
var tasks = [
  function(collection, key, callback) {
    setTimeout(function() {
      callback(null, array);
    }, delay.shift());
  },
  function(collection, key, callback) {
    callback(null, array);
  },
  function(value, key, callback) {
    setTimeout(function() {
      order.push(value);
      callback();
    }, value * 10);
  }
];

async.multiEach(collection, tasks, function(err) {
  assert.deepEqual(order, [
    1, 1, 1,
    2, 2, 2,
    1, 1, 1,
    3, 3, 3,
    2, 2, 2,
    3, 3, 3
  ]);
});

Speed Comparison

sample script

sample.waterfall.js
'use strict';
var comparator = require('func-comparator');
var _ = require('lodash');
var async = require('async');
var neo_async = require('neo-async');

// roop count
var count = 10;
// sampling times
var times = 1000;
var array = _.sample(_.times(count), count);
var tasks = _.map(array, function(n, i) {
  if (i === 0) {
    return function(next) {
      next(null, n);
    };
  }
  return function(total, next) {
    next(null, total + n);
  };
});
var funcs = {
  'async': function(callback) {
    async.waterfall(tasks, callback);
  },
  'neo-async': function(callback) {
    neo_async.waterfall(tasks, callback);
  }
};

comparator
.set(funcs)
.option({
  async: true,
  times: times
})
.start()
.result(function(err, res) {
  console.log(res);
});

execute

# using garbage collection per execute
$ node --exsepo_gc speed_test/controlFlow/sample.waterfall.js

result

{ async:
   { min: 91.79,
     max: 1751.06,
     average: 275.01,
     variance: 55185.67,
     standard_deviation: 234.91,
     vs: { 'neo-async': 41 } }, //[%] 100 * neo_async.average / async.average
  'neo-async':
   { min: 16.55,
     max: 600.16,
     average: 112.78,
     variance: 11310.35,
     standard_deviation: 106.35,
     vs: { async: 243.84 } } }

Results

Collections

functioncounttimesasync/neo-async
concat101000125.77
concatSeries101000101.81
detect101000282.77
detectSeries101000112.06
each101000111.66
eachSeries10100094.08
eachLimit101000154.82
every101000217.7
filter101000279.27
filterSeries101000242.97
map101000473.08
mapSeries101000359.44
mapLimit101000590.42
reduce101000102.36
reduceRight101000341.52
some101000266.78
sortBy101000135.18

ControlFlow

functioncounttimesasync/neo-async
waterfall101000243.84
waterfall501000413.35
parallel101000145.45
parallelLimit101000196.36
series10500140.98

Keywords

FAQs

Last updated on 27 Dec 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc