
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Stepper and Grouper classes for running an arbitrary number of tasks in series or parallel
Stepper and Grouper classes for running an arbitrary number of tasks in series or parallel
Eliminate some boilerplate when using step.
stepper
add()
methodwalk()
methodRunning some sync and async tasks one after another
var Stepper = require('../lib/stepper').Stepper;
var stepper = new Stepper();
// add steps
stepper.add(function(err, val) {
console.log('running step 1 (sync)');
return 1;
});
stepper.add(function(err, val) {
if (err) throw err;
console.log('running step 2 (sync)');
return 2;
});
stepper.add(function(err, val) {
if (err) throw err;
console.log('running step 3 (async)');
var self = this;
console.log('wait 2 seconds...');
setTimeout(function() {
console.log('completed step 3 (async)');
self();
}, 2000);
});
stepper.add(function(err, val) {
console.log('running step 4 (sync)');
return 4;
});
// handle completion
var onComplete = function(err, val) {
if (err) throw err;
console.log('stepping is complete');
console.log('return value: ' + val + '\n');
};
// run steps
console.log('\nstart stepping...');
stepper.walk(onComplete);
Output
start stepping...
running step 1 (sync)
running step 2 (sync)
running step 3 (async)
wait 2 seconds...
completed step 3 (async)
running step 4 (sync)
stepping is complete
return value: 4
Run some async tasks in parallel
var Grouper = require('../lib/stepper').Grouper;
var grouper = new Grouper();
// setup group functions
grouper.add(function(fn) {
console.log('running step 1 (async)');
console.log('wait 3 seconds...');
setTimeout(function() {
console.log('completed step 1 (async)');
fn(null, 1);
}, (1000 * 3));
});
grouper.add(function(fn) {
console.log('running step 2 (async)');
console.log('wait 2 seconds...');
setTimeout(function() {
console.log('completed step 2 (async)');
fn(null, 2);
}, (1000 * 2));
});
grouper.add(function(fn) {
console.log('running step 3 (async)');
console.log('wait 1 second...');
setTimeout(function() {
console.log('completed step 3 (async)');
fn(null, 3);
}, (1000));
});
// handle completion
var onComplete = function(err, vals) {
if (err) throw err;
console.log('group is complete');
console.log('return values: ' + vals + '\n');
};
// run steps
console.log('\nstart group...');
grouper.walk(onComplete);
Output
start group...
running step 1 (async)
wait 3 seconds...
running step 2 (async)
wait 2 seconds...
running step 3 (async)
wait 1 second...
completed step 3 (async)
completed step 2 (async)
completed step 1 (async)
group is complete
return values: 1,2,3
You can also add()
Stepper
s and Grouper
s. See examples/nesting.js
Inspired by and dependent on step
FAQs
Stepper and Grouper classes for running an arbitrary number of tasks in series or parallel
The npm package stepper receives a total of 99 weekly downloads. As such, stepper popularity was classified as not popular.
We found that stepper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.