Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
run-parallel
Advanced tools
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.
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 17,828,753 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.