Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
run-parallel
Advanced tools
Run an array of functions in parallel
Weekly downloads
Package description
The run-parallel npm package is designed to run multiple functions in parallel, without waiting until the previous function has completed. It is particularly useful for executing asynchronous tasks concurrently, such as I/O operations, in an efficient manner. Once all tasks have completed, a final callback is called with the results of each task.
Running multiple asynchronous tasks in parallel
This feature allows for executing multiple asynchronous tasks concurrently. The code sample demonstrates how to use run-parallel to execute two tasks in parallel, each completing at different times but being processed together.
const runParallel = require('run-parallel')
const tasks = [
function(callback) {
setTimeout(function() {
callback(null, 'one')
}, 200)
},
function(callback) {
setTimeout(function() {
callback(null, 'two')
}, 100)
}
]
runParallel(tasks, function(err, results) {
console.log(results) // ['one', 'two']
})
The async package offers a wide range of functions for working with asynchronous JavaScript, including parallel execution. Compared to run-parallel, async provides a broader set of utilities for handling asynchronous operations, making it more versatile but potentially heavier for projects only needing parallel execution.
p-map is a promise-based map function designed for running multiple promises in parallel, with support for concurrency limits. Unlike run-parallel, which uses callbacks, p-map utilizes promises, making it a better fit for modern asynchronous patterns in JavaScript.
ParallelJS is a library for parallel programming with JavaScript, allowing for the execution of code in parallel processes. It differs from run-parallel by focusing on parallel computation rather than just asynchronous task execution, potentially offering more power for CPU-bound tasks.
Readme
npm install run-parallel
Run the tasks
array of functions in parallel, without waiting until the previous
function has completed. If any of the functions pass an error to its callback, the main
callback
is immediately called with the value of the error. Once the tasks
have
completed, the results are passed to the final callback
as an array.
It is also possible to use an object instead of an array. Each property will be run as a
function and the results will be passed to the final callback
as an object instead of
an array. This can be a more readable way of handling the results.
tasks
- An array or object 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 (or object) containing all the result
arguments passed to the task callbacks.var parallel = require('run-parallel')
parallel([
function (callback) {
setTimeout(function () {
callback(null, 'one')
}, 200)
},
function (callback) {
setTimeout(function () {
callback(null, 'two')
}, 100)
}
],
// optional callback
function (err, results) {
// the results array will equal ['one','two'] even though
// the second function had a shorter timeout.
})
This module is basically equavalent to
async.parallel
, but it's
handy to just have the one function 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 parallel
The npm package run-parallel receives a total of 27,303,070 weekly downloads. As such, run-parallel popularity was classified as popular.
We found that run-parallel 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
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.