Socket
Socket
Sign inDemoInstall

run-series

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

run-series

Run an array of functions in series


Version published
Maintainers
1
Weekly downloads
1,222,042
decreased by-32.09%

Weekly downloads

Package description

What is run-series?

The run-series npm package is a utility that allows you to run an array of functions in series, each one running once the previous function has completed. If any functions in the series pass an error to its callback, no more functions are run, and the main callback is immediately called with the error. This package is particularly useful for managing sequences of asynchronous tasks in a clean and straightforward manner.

What are run-series's main functionalities?

Running tasks in series

This feature allows you to run multiple tasks one after another. Each task is a function that takes a callback as its only argument. Once a task completes, it calls the callback, optionally passing an error and results. If a task passes an error, the series is stopped, and the final callback is called with the error. Otherwise, after all tasks have completed, the final callback is called with an array of results.

const series = require('run-series');

series([
  function(callback) {
    // Task 1
    callback(null, 'result of task 1');
  },
  function(callback) {
    // Task 2
    callback(null, 'result of task 2');
  }
], function(err, results) {
  if (err) throw err;
  console.log(results); // ['result of task 1', 'result of task 2']
});

Other packages similar to run-series

Readme

Source

run-series travis npm downloads javascript style guide

Run an array of functions in series

series Sauce Test Status

install

npm install run-series

usage

series(tasks, [callback])

Run the functions in the tasks array in series, each one running once the previous function has completed. If any functions in the series pass an error to its callback, no more functions are run, and callback is immediately called with the value of the error. Otherwise, callback receives an array of results when tasks have completed.

arguments
  • tasks - An array containing functions to run, each function is passed a callback(err, result) which it must call on completion with an error err (which can be null) and an optional result value.
  • callback(err, results) - An optional callback to run once all the functions have completed. This function gets a results array containing all the result arguments passed to the task callbacks.
example
var series = require('run-series')

series([
  function (callback) {
    // do some stuff ...
    callback(null, 'one')
  },
  function (callback) {
    // do some stuff ...
    callback(null, 'two')
  }
],
// optional callback
function (err, results) {
  // the results array will equal ['one','two']
})

This module is basically equavalent to async.series, but it's handy to just have the functions you need instead of the kitchen sink. Modularity! Especially handy if you're serving to the browser and need to reduce your javascript bundle size.

Works great in the browser with browserify!

see also

license

MIT. Copyright (c) Feross Aboukhadijeh.

Keywords

FAQs

Last updated on 27 Oct 2020

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc