How to write simple, understandable, easily maintainable code that runs several asynchronous functions in javascript / jQuery sequentially? (when one works, the other should run)
The following example illustrates my question:
function f1(){ setTimeout( function(){ console.log(1); }, 30); } function f2(){ setTimeout( function(){ console.log(2); }, 20); } function f3(){ setTimeout( function(){ console.log(3); }, 10); } f1(); f2(); f3(); at the output of 3 2 1 how to do something would give out 1 2 3?
Preferably without callbacks - because if you need to run more than two functions in succession, it is already hard to read. Much suggests that a solution is possible using the $ .Deferred object, but has not yet seen a reasonable option.
A similar question was asked more than once, but for some reason I could not find the answer that would suit me.