No promises, no async etc I wondered if this pattern is acceptable - my function is called and i'm passed a callback. I need to do 2 things before I can call that back:
function doSomething(..args.., callbackThatNeeds1And2DoneFirst){
var done1 = false;
var res1 = someAsync1(function call1callback(){
//blah
done1 = true;
maybeComplete();
});
var done2 = false;
var res2 = someAsync2(function call2callback(){
//blah
done2 = true;
maybeComplete();
});
function maybeComplete(){
if(done1 && done2){
callbackThatNeeds1And2DoneFirst();
}
}
}
I suppose the questions is about variable scope - can multiple "concurrent" executions interfere with each other's values for done1 and done2, or does each call get its own variable scope?