I have four requests that each have their own callback and can fire in any order. However, I need all the callbacks to finish successfully before executing mergeData
.
The issue with my current approach is that the initial parameter values do not refresh once waitForSync
is called (and I am not confident in this method). Can anyone guide me in the right direction?
var heroes = requestDataFromAPI('heroes');
var weapons = requestDataFromAPI('weapons');
var races = requestDataFromAPI('races');
var jobs = requestDataFromAPI('jobs');
waitForSync(heroes, weapons, races, jobs);
...
function waitForSync(heroes, weapons, races, jobs){
if (heroes && weapons && races && jobs) {
mergeData(heroes, weapons, races, jobs);
}
else {
setTimeout(waitForSync, '500', heroes, weapons, races, jobs);
}
}