Tool use to synchronize asynchronous callbacks together. This calls the main callback when the correct number of calls is reached.
npm install --save callback_sync
Here is a small example on how to use this module
const syncer = require("callback_sync");
var sync = syncer(4, function(err, val) {
console.log("sync",err,val);
});
sync(null, 8);
sync(null, 6);
sync(new Error("erreur"), 10);
sync(null, 4);This is the only function of the module.
targetCountis the number of calls to wait before calling back.callbackis the function to callback once the number is reached or there is an errorerris the error object (nullif no error)datais an array of values given through every callback (empty on error)
For every call to the returned method, the data and error will be aggregated in an array.
This syncer can be used as a callback(err, data) to other asynchronous functions (it was build for this).
Copyright (c) 2018, Weaverize SAS. All rights reserved. Contact: [email protected].