Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
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.
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
});
The original async package offers a wide array of functions for working with asynchronous code. Neo-async claims to offer similar functionality with improved performance.
Bluebird is a full-featured promise library with a focus on innovative features and performance. It can be used as an alternative to neo-async for handling asynchronous operations using promises instead of callbacks.
Q is a tool for making and composing asynchronous promises in JavaScript. It's an older promise library that can serve similar purposes to neo-async but with a different style of handling async operations.
Neo-Async is compatible with Async.js, it is faster and has more feature. Async is a utilty module which provides staright-forward.
<script src="async.min.js"></script>
require(['async.min'], function(async) {});
$ npm install neo-async
var async = require('neo-async');
$ npm install neo-async
$ ln -s ./node_modules/neo-async ./node_modules/async
var async = require('async');
concat
concatSeries
concatLimit
detect
detectSeries
detectLimit
each
eachSeries
eachLimit
every
everySeries
everyLimit
filter
filterSeries
filterLimit
forEach
forEachSeries
forEachLimit
map
mapSeries
mapLimit
multiEach
pick
pickSeries
pickLimit
reduce
reduceRight
reject
rejectSeries
rejectLimit
select
selectSeries
selectLimit
some
someSeries
someLimit
sortBy
sortBySeries
sortByLimit
transform
transformSeries
transformLimit
Arguments
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]);
});
Aliases
async.forEach
Arguments
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]);
});
Aliases
async.forEachSeries
Arguments
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]);
});
Aliases
async.forEachLimit
Arguments
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]);
});
Arguments
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
]);
});
'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 } } }
Collections
function | count | times | async/neo-async |
---|---|---|---|
concat | 10 | 1000 | 125.77 |
concatSeries | 10 | 1000 | 101.81 |
detect | 10 | 1000 | 282.77 |
detectSeries | 10 | 1000 | 112.06 |
each | 10 | 1000 | 111.66 |
eachSeries | 10 | 1000 | 94.08 |
eachLimit | 10 | 1000 | 154.82 |
every | 10 | 1000 | 217.7 |
filter | 10 | 1000 | 279.27 |
filterSeries | 10 | 1000 | 242.97 |
map | 10 | 1000 | 473.08 |
mapSeries | 10 | 1000 | 359.44 |
mapLimit | 10 | 1000 | 590.42 |
reduce | 10 | 1000 | 102.36 |
reduceRight | 10 | 1000 | 341.52 |
some | 10 | 1000 | 266.78 |
sortBy | 10 | 1000 | 135.18 |
ControlFlow
function | count | times | async/neo-async |
---|---|---|---|
waterfall | 10 | 1000 | 243.84 |
waterfall | 50 | 1000 | 413.35 |
parallel | 10 | 1000 | 145.45 |
parallelLimit | 10 | 1000 | 196.36 |
series | 10 | 500 | 140.98 |
FAQs
Neo-Async is a drop-in replacement for Async, it almost fully covers its functionality and runs faster
The npm package neo-async receives a total of 24,349,999 weekly downloads. As such, neo-async popularity was classified as popular.
We found that neo-async demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.