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.
a-sync-waterfall
Advanced tools
Runs a list of async tasks, passing the results of each into the next one
The a-sync-waterfall npm package is used to run an array of asynchronous functions in series, each passing their results to the next in the array. However, if any of the functions pass an error to the callback, the next function is not executed, and the main callback is immediately called with the error.
Running asynchronous tasks in series
This feature allows you to run multiple asynchronous tasks in series, where each task waits for the previous one to complete before starting. The results of each task are passed to the next task in the array.
const waterfall = require('a-sync-waterfall');
waterfall([
function(callback) {
setTimeout(() => {
console.log('Task 1');
callback(null, 'one');
}, 1000);
},
function(arg1, callback) {
setTimeout(() => {
console.log('Task 2');
callback(null, 'two');
}, 500);
},
function(arg1, callback) {
setTimeout(() => {
console.log('Task 3');
callback(null, 'three');
}, 100);
}
], function (err, result) {
if (err) {
console.error('Error:', err);
} else {
console.log('All tasks completed. Final result:', result);
}
});
Error handling in series of tasks
This feature demonstrates how errors are handled in a series of tasks. If any task passes an error to the callback, the subsequent tasks are not executed, and the main callback is immediately called with the error.
const waterfall = require('a-sync-waterfall');
waterfall([
function(callback) {
setTimeout(() => {
console.log('Task 1');
callback(null, 'one');
}, 1000);
},
function(arg1, callback) {
setTimeout(() => {
console.log('Task 2');
callback('Error in Task 2');
}, 500);
},
function(arg1, callback) {
setTimeout(() => {
console.log('Task 3');
callback(null, 'three');
}, 100);
}
], function (err, result) {
if (err) {
console.error('Error:', err);
} else {
console.log('All tasks completed. Final result:', result);
}
});
The async package provides a collection of functions for working with asynchronous JavaScript. It includes methods for running tasks in series, parallel, and other control flow patterns. Compared to a-sync-waterfall, async offers a broader range of utilities and more flexibility in handling asynchronous operations.
The async-waterfall package is another implementation of the waterfall pattern for running asynchronous tasks in series. It is similar to a-sync-waterfall but is part of the larger async library, which provides additional utilities for managing asynchronous code.
Neo-async is a high-performance drop-in replacement for async. It provides similar functionality with a focus on speed and efficiency. Like async, it includes methods for running tasks in series, parallel, and other control flow patterns, making it a versatile alternative to a-sync-waterfall.
Simple, isolated sync/async waterfall module for JavaScript.
Runs an array of functions in series, each passing their results to the next in the array. However, if any of the functions pass an error to the callback, the next function is not executed and the main callback is immediately called with the error.
For browsers and node.js.
npm install a-sync-waterfall
if you’re using node.js.waterfall(tasks, optionalCallback, forceAsync);
callback(err, result1, result2, ...)
it must call on completion. The first
argument is an error (which can be null) and any further arguments will be
passed as arguments in order to the next task.var waterfall = require('a-sync-waterfall');
waterfall(tasks, callback);
var waterfall = require('a-sync-waterfall');
waterfall(tasks, callback);
// Default:
window.waterfall(tasks, callback);
waterfall([
function(callback){
callback(null, 'one', 'two');
},
function(arg1, arg2, callback){
callback(null, 'three');
},
function(arg1, callback){
// arg1 now equals 'three'
callback(null, 'done');
}
], function (err, result) {
// result now equals 'done'
});
/* basic - no arguments */
waterfall(myArray.map(function (arrayItem) {
return function (nextCallback) {
// same execution for each item, call the next one when done
doAsyncThingsWith(arrayItem, nextCallback);
}}));
/* with arguments, initializer function, and final callback */
waterfall([function initializer (firstMapFunction) {
firstMapFunction(null, initialValue);
}].concat(myArray.map(function (arrayItem) {
return function (lastItemResult, nextCallback) {
// same execution for each item in the array
var itemResult = doThingsWith(arrayItem, lastItemResult);
// results carried along from each to the next
nextCallback(null, itemResult);
}})), function (err, finalResult) {
// final callback
});
Hat tip to Caolan McMahon and Paul Miller, whose prior contributions this is based upon. Also Elan Shanker from which this rep is forked
FAQs
Runs a list of async tasks, passing the results of each into the next one
We found that a-sync-waterfall 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.
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.