What is a best way to execute function until before call is finished?
Example JavaScript function:
var notifyState = function(state) {
setTimeout(function () {
/*Do something*/
}, 2000);
};
Then I call function twice:
notifyState('State1');
notifyState('State2');
This functions executing in paraller. What best way to execute them sequentially? I can only modify notifyState
function. notifyState
can execute only with one parameter.
Update:
Function notifyState
informs what actual state is in flash game. It saves it in html code, when state change then state is override. In selenium test I downloading state from html code, but state change too fast that selenium not noticed this, so I tried sleep JavaScript.