Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
async-each
Advanced tools
No-bullshit, ultra-simple, 35-lines-of-code async parallel forEach / map function for JavaScript.
The async-each package is a small, zero-dependency utility module for Node.js that provides a simple way to iterate over an array asynchronously. It allows you to apply a function to each item in an array in parallel, without waiting for the previous function call to complete, making it useful for performing IO-bound tasks or operations that are CPU-intensive but can be run concurrently.
Asynchronous iteration over an array
This feature allows you to asynchronously process each item in an array. The provided code sample demonstrates how async-each can be used to log each item in an array with a delay of 1 second between each log, simulating an asynchronous operation like reading files or making HTTP requests.
const asyncEach = require('async-each');
const myArray = [1, 2, 3, 4];
asyncEach(myArray, (item, callback) => {
setTimeout(() => {
console.log(item);
callback();
}, 1000);
}, (err) => {
if (err) throw err;
console.log('All items have been processed.');
});
The 'async' package is a comprehensive collection of utility functions for working with asynchronous JavaScript. It offers much more than just asynchronous iteration, including control flow, collection manipulation, and utility functions. Compared to async-each, it is more feature-rich but also larger in size, making async-each a lightweight alternative for projects that only require asynchronous iteration.
Bluebird is a powerful promise library that, among many other features, offers utilities for concurrent execution of promises, which can be used for asynchronous iteration similar to async-each. Bluebird is known for its performance and extensive feature set. It is a good choice if you are already working with promises and need a broad set of features beyond asynchronous iteration.
p-each-series is a package that allows for serial iteration over an array of items with promises. Unlike async-each, which performs iterations in parallel, p-each-series ensures that each item is processed one after the other, waiting for the current promise to resolve before moving to the next. This is useful for tasks that must be done in order but still benefit from asynchronous execution.
No-bullshit, ultra-simple, 40-lines-of-code async parallel forEach function for JavaScript.
We don't need junky 30K async libs. Really.
For browsers and node.js.
npm install async-each
if you're using NPM.
For browsers, just include async-each before your scripts and use global variable asyncEach
each(array, iterator, callback)
— Array
, Function
, (optional) Function
iterator(item, next)
receives current item and a callback that will mark the item as done. next
callback receives optional error, transformedItem
arguments.callback(error, transformedArray)
optionally receives first error and transformed result Array
.var each = require('async-each');
each(['a.js', 'b.js', 'c.js'], fs.readFile, function(error, contents) {
if (error) console.error(error);
console.log('Contents for a, b and c:', contents);
});
asyncEach(list, fn, callback); // use global var in browser
The MIT License (MIT)
Copyright (c) 2016 Paul Miller (paulmillr.com)
See LICENSE file.
FAQs
No-bullshit, ultra-simple, 35-lines-of-code async parallel forEach / map function for JavaScript.
We found that async-each demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.