![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
fastparallel
Advanced tools
The fastparallel npm package is designed to handle parallel function execution efficiently. It allows you to run multiple asynchronous tasks in parallel and collect their results once all tasks are completed. This can be particularly useful for scenarios where you need to perform multiple I/O-bound operations concurrently.
Parallel Execution
This feature allows you to execute multiple asynchronous tasks in parallel. The provided code sample demonstrates how to run two tasks concurrently and collect their results once both tasks are completed.
const fastparallel = require('fastparallel')();
function task1(arg, cb) {
setTimeout(() => cb(null, 'result1'), 100);
}
function task2(arg, cb) {
setTimeout(() => cb(null, 'result2'), 200);
}
fastparallel(null, [task1, task2], 'argument', (err, results) => {
if (err) throw err;
console.log(results); // ['result1', 'result2']
});
Error Handling
This feature demonstrates how fastparallel handles errors in parallel tasks. If any task encounters an error, the final callback receives the error, and the results array is not populated.
const fastparallel = require('fastparallel')();
function task1(arg, cb) {
setTimeout(() => cb(null, 'result1'), 100);
}
function task2(arg, cb) {
setTimeout(() => cb(new Error('Something went wrong'), null), 200);
}
fastparallel(null, [task1, task2], 'argument', (err, results) => {
if (err) {
console.error(err.message); // 'Something went wrong'
} else {
console.log(results);
}
});
The async package provides a wide range of utilities for working with asynchronous JavaScript. It includes methods for parallel execution, series execution, and more. Compared to fastparallel, async offers a broader set of functionalities but may be less performant for simple parallel execution tasks.
Bluebird is a fully-featured Promise library that includes methods for managing multiple promises in parallel. It offers more advanced features like promise cancellation and long stack traces. While it is more feature-rich, it may be overkill for simple parallel execution scenarios that fastparallel handles efficiently.
p-map is a smaller utility that maps over promises concurrently. It allows you to control the concurrency level, making it more flexible for certain use cases. However, it is less specialized than fastparallel for simple parallel function execution.
Zero-overhead parallel function call for node.js. Also supports each and map!
Benchmark for doing 3 calls setImmediate
1 million times:
setImmediate
: 2450msasync.parallel
: 6347msasync.each
: 3182msasync.map
: 5026msfastparallel
with results: 2623msfastparallel
without results: 2556msfastparallel
map: 2622msfastparallel
each: 2594msThese benchmarks where taken via bench.js
on iojs 1.8.1, on a MacBook
Pro Retina 2014.
If you need zero-overhead series function call, check out fastseries.
var parallel = require('fastparallel')({
// this is a function that will be called
// when a parallel completes
released: completed,
// if you want the results, then here you are
results: true
})
parallel(
{}, // what will be this in the functions
[something, something, something], // functions to call
42, // the first argument of the functions
done // the function to be called when the parallel ends
)
function something (arg, cb) {
setImmediate(cb, null, 'myresult')
}
function done (err, results) {
console.log('parallel completed, results:', results)
}
function completed () {
console.log('parallel completed!')
}
var parallel = require('fastparallel')({
// this is a function that will be called
// when a parallel completes
released: completed,
// if you want the results, then here you are
// passing false disables map
results: true
})
parallel(
{}, // what will be this in the functions
something, // functions to call
[1, 2, 3], // the first argument of the functions
done // the function to be called when the parallel ends
)
function something (arg, cb) {
setImmediate(cb, null, 'myresult')
}
function done (err, results) {
console.log('parallel completed, results:', results)
}
function completed () {
console.log('parallel completed!')
}
The results
array will be non-ordered, and the done
function will
be called only once, even if more than one error happen.
This library works by caching the latest used function, so that running a new parallel does not cause any memory allocations.
ISC
FAQs
Zero-overhead asynchronous parallel/each/map function call
The npm package fastparallel receives a total of 219,879 weekly downloads. As such, fastparallel popularity was classified as popular.
We found that fastparallel 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.