
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
multiple-callbacks
Advanced tools
Execute a callback after the execution of other callbacks.
Note: If you're reading this, probably you want to use Promises instead of this library
Install with npm install multiple-callbacks
execute multipleCallbacks with the quantity of callbacks that will be executed before and the callback.
multipleCallbacks(times, callback, name); return a function.
Every time that this function is executed count one callback as executed.
var multipleCallbacks = require('multiple-callbacks');
var cb = multipleCallbacks(2, makeHamburgers);
getMeat();
getBread();
function getMeat () {
/*Async operation*/
setTimeout(cb, 1000);
}
function getBread () {
/*Async operation*/
setTimeout(cb, 1000);
}
function makeHamburgers () {
console.log('I’m lovin’ it!');
}
You can change the execution times needed to execute the callback at any time with:
var multipleCallbacks = require('multiple-callbacks');
var cb = multipleCallbacks(times, callback);
cb.setTimesToFire(newTimes);
Other methods are:
getTimesToFire: Return the needed quantity of callbacks executions to execute your callback.
getFiredTimes: Return the times that the callback returned by MultipleCallbacks has been fired.
sumTimesToFire: Sum a quantity to the needed quantity of callbacks executions to execute your callback.
For debbug porposes you can pass a name to the constructor. multipleCallbacks(times, callback, name); It uses de debug module for show the name on every callback execution.
The name of debug function (for view the log) are MultipleCallbacks:log and MultipleCallbacks:warning. See the debug documentation for more info.
If you don't know the quantity of times that the callback will be executed, you can pass false to 'multiple-callbacks' to cancel the execution on the final callback until you provide the quantity of calls to execute the final callback.
A weird example:
var multipleCallbacks = require('multiple-callbacks');
var exTime = 0;
var callback = multipleCallbacks(false, function () {
done();
});
services.forEach(function (service) {
if(service.updated === false){
service.doSyncOrAsyncStuff(callback)
exTime++;
}
});
cb.setTimesToFire(exTime);
Let's view the first example with data:
var multipleCallbacks = require('multiple-callbacks');
var cb = multipleCallbacks(2, makeHamburgers);
getMeat();
getBread();
function getMeat () {
/*Async operation*/
setTimeout(function () {
cb(new Meat());
}, 1000);
}
function getBread () {
/*Async operation*/
setTimeout(function () {
cb(new Bread());
}, 1000);
}
function makeHamburgers (ingredients) {
var hamburger = new Hamburger();
for (var i = ingredients.length - 1; i >= 0; i--) {
var ingredient = ingredients[i];
hamburger.addIngredient(ingredient);
}
console.log('I’m lovin’ it!');
}
If only one callback has returned data, multipleCallbacks don't pass an Array to the user callback. Instead pass the data itself.
FAQs
execute a callback after the execution of other callbacks
We found that multiple-callbacks 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.