Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
run-series
Advanced tools
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.
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']
});
The 'async' package provides a wide range of functions for working with asynchronous JavaScript, including a 'series' method that behaves similarly to run-series. However, 'async' offers much more functionality beyond just running tasks in series, such as parallel execution, waterfall flows, and more, making it a more versatile choice for complex asynchronous control flow.
Neo-async is a drop-in replacement for the 'async' library, designed to be faster and more lightweight. It offers a 'series' function similar to that of run-series and async, but with performance improvements and additional features for handling asynchronous operations, making it a good choice for performance-critical applications that require complex flow control.
npm install run-series
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.
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.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']
})
Runs the tasks
array of functions in series, each passing their results to the next in
the array. However, if any of the tasks
pass an error to their own callback, the next
function is not executed, and the main callback
is immediately called with the error.
tasks
- An array of functions to run, each function is passed a
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.callback(err, [results])
- An optional callback to run once all the functions have
completed. This will be passed the results of the last task's callback.var series = require('run-series')
series.waterfall([
function (callback) {
callback(null, 'one', 'two')
},
function (arg1, arg2, callback) {
// arg1 now equals 'one' and arg2 now equals 'two'
callback(null, 'three')
},
function (arg1, callback) {
// arg1 now equals 'three'
callback(null, 'done', 'wohoo')
}
], function (err, result1, result2) {
// result1 now equals 'done'
// result2 now equals 'wohoo'
})
This module is basically equavalent to
async.series
and
async.waterfall
, 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!
MIT. Copyright (c) Feross Aboukhadijeh.
FAQs
Run an array of functions in series
The npm package run-series receives a total of 1,099,074 weekly downloads. As such, run-series popularity was classified as popular.
We found that run-series 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
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.