MultipleCallbacks
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
Usage
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 = ;var cb = ;;;{/*Async operation*/;}{/*Async operation*/;}{console;}
You can change the execution times needed to execute the callback at any time with:
var multipleCallbacks = ;var cb = ;cb;
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.
Indeterminated quantity of callbacks executions
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 = ;var exTime = 0;var callback =;services;cb;
Your async functions return data
Let's view the first example with data:
var multipleCallbacks = ;var cb = ;;;{/*Async operation*/;}{/*Async operation*/;}{var hamburger = ;for var i = ingredientslength - 1; i >= 0; i--var ingredient = ingredientsi;hamburger;console;}
If only one callback has returned data, multipleCallbacks don't pass an Array to the user callback. Instead pass the data itself.