Gathering detailed insights and metrics for node-async-runner
Gathering detailed insights and metrics for node-async-runner
Gathering detailed insights and metrics for node-async-runner
Gathering detailed insights and metrics for node-async-runner
async-benchmark-runner
Benchmark runner for node focusing on measuring asynchronous code using promises.
@thi.ng/testament
Minimal, rational & TypeScript-friendly test runner, result export as CSV/JSON, watch mode, file fixtures
cynic
async testing framework for es-modules
bree
The best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support. Works in Node v12.17.0+, uses worker threads to spawn sandboxed processes, and supports async/await, retries, throttling, concurrency, and cancelab
Run asynchronous tasks in a persistent order.
npm install node-async-runner
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
3,059
Last Day
1
Last Week
1
Last Month
14
Last Year
247
MIT License
1 Stars
30 Commits
1 Watchers
3 Branches
1 Contributors
Updated on Oct 30, 2024
Minified
Minified + Gzipped
Latest Version
2.0.0-rc.1
Package Id
node-async-runner@2.0.0-rc.1
Unpacked Size
13.75 kB
Size
4.43 kB
File Count
6
NPM Version
10.5.2
Node Version
20.13.1
Published on
Sep 14, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-80%
1
Compared to previous week
Last Month
-54.8%
14
Compared to previous month
Last Year
60.4%
247
Compared to previous year
No dependencies detected.
This update of this package is in development, do not use in production
AsyncRunner is a Node.js utility for managing and executing asynchronous tasks with controlled concurrency. Version 2.0.0 introduces modern JavaScript features (async/await
), task hashing, task naming, and enhanced event handling.
async/await
.'next'
, 'done'
, 'error'
) to track task execution.You can install AsyncRunner via npm:
1npm install async-runner
Or add the async-runner.js
file to your project.
1const AsyncRunner = require('async-runner'); 2 3const runner = new AsyncRunner({ maxThreads: 5, stopOnError: false }); 4 5runner.add([ 6 async function () { 7 // Your async code here 8 }, 9 // ... more tasks 10]); 11 12runner.run().then((results) => { 13 console.log('Results:', results); 14});
Tasks can be added as functions or as objects with a task
function and an optional name
:
1// Adding a single task function 2runner.add(async function () { 3 // Task code 4}); 5 6// Adding tasks with names 7runner.add([ 8 { 9 task: async function () { 10 // Task code 11 }, 12 name: 'Task One', 13 }, 14 { 15 task: async function () { 16 // Task code 17 }, 18 name: 'Task Two', 19 }, 20]);
You can listen to various events emitted by the runner:
1runner.on('next', (taskFunction, taskHash, taskName) => { 2 console.log(`Starting task: ${taskName || 'Unnamed Task'}`); 3 console.log(`Task Hash: ${taskHash}`); 4}); 5 6runner.on('done', (results, errors) => { 7 console.log('All tasks completed.'); 8 console.log('Results:', results); 9 if (errors && errors.length > 0) { 10 console.log('Errors:', errors); 11 } 12}); 13 14runner.on('error', (err) => { 15 console.error('Execution halted due to error:', err); 16});
The maxThreads
option controls the maximum number of tasks that can run concurrently. Adjust it according to your needs:
1const runner = new AsyncRunner({ maxThreads: 3 });
maxThreads
to 1
will execute tasks sequentially.1new AsyncRunner(options)
maxThreads
(number, default 10
): Maximum number of concurrent tasks.stopOnError
(boolean, default false
): Stop execution upon encountering an error.Add tasks to the runner.
task
(function): The task function to execute.name
(string, optional): A name for the task.Example:
1runner.add(async function () { 2 // Task code 3}); 4 5runner.add([ 6 { 7 task: async function () { 8 // Task code 9 }, 10 name: 'Task Name', 11 }, 12]);
Execute the tasks.
Promise
that resolves with the results array or rejects with an error if stopOnError
is true
.Example:
1runner.run().then((results) => { 2 // Handle results 3}).catch((error) => { 4 // Handle error 5});
'next': Emitted before a task starts execution.
taskFunction
(function): The task function.taskHash
(string): Unique hash of the task.taskName
(string or null): Name of the task.'done': Emitted when all tasks have completed.
results
(array): Array of results from tasks.errors
(array): Array of errors (if any).'error': Emitted when an error occurs and stopOnError
is true
.
error
(Error): The error that occurred.Example:
1runner.on('next', (taskFunction, taskHash, taskName) => { 2 // Handle event 3}); 4 5runner.on('done', (results, errors) => { 6 // Handle completion 7}); 8 9runner.on('error', (err) => { 10 // Handle error 11});
1const AsyncRunner = require('async-runner'); 2 3const runner = new AsyncRunner({ maxThreads: 2, stopOnError: false }); 4 5runner.add([ 6 async function () { 7 await new Promise((resolve) => setTimeout(resolve, 1000)); 8 return 'Result 1'; 9 }, 10 async function () { 11 await new Promise((resolve) => setTimeout(resolve, 500)); 12 return 'Result 2'; 13 }, 14]); 15 16runner.run().then((results) => { 17 console.log('Results:', results); 18});
1const AsyncRunner = require('async-runner'); 2 3const runner = new AsyncRunner({ maxThreads: 2, stopOnError: false }); 4 5runner.add([ 6 { 7 task: async function () { 8 await new Promise((resolve) => setTimeout(resolve, 1000)); 9 return 'Result 1'; 10 }, 11 name: 'Fetch Data', 12 }, 13 { 14 task: async function () { 15 await new Promise((resolve) => setTimeout(resolve, 500)); 16 return 'Result 2'; 17 }, 18 name: 'Process Data', 19 }, 20]); 21 22runner.on('next', (taskFunction, taskHash, taskName) => { 23 console.log(`Starting task: ${taskName}`); 24 console.log(`Task Hash: ${taskHash}`); 25}); 26 27runner.on('done', (results, errors) => { 28 console.log('All tasks completed.'); 29 console.log('Results:', results); 30}); 31 32runner.run();
async/await
for modern Node.js support.'next'
event emitted before each task execution.No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/15 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More