Socket
Book a DemoInstallSign in
Socket

a-sync-waterfall

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-sync-waterfall

Runs a list of async tasks, passing the results of each into the next one

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
1.1M
7.91%
Maintainers
1
Weekly downloads
 
Created

What is a-sync-waterfall?

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.

What are a-sync-waterfall's main functionalities?

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);
  }
});

Other packages similar to a-sync-waterfall

Keywords

async

FAQs

Package last updated on 31 Aug 2018

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.