For better structure of my script I want to eliminate .then() blocks. I.E. turn
callAsyncFunction().then( (result) => {
console.log("done");
callAnotherAsyncFunction().then( (result2) => {
console.log("also done");
// further steps ...
});
});
into
callAsyncFunction().wait();
console.log("done");
callAnotherAsyncfunction().wait();
console.log("also done");
// further steps ...
I know JavaScript does not support blocking functions like wait() for a reason. But for my purpose it would be just perfect if there was a compiler/transcriptor that turns the code from the 2. example into the code of the 1st example. So it would not actually block a call but allow a better representation for callbacks. Is there a script language like dart maybe, that compiles into JavaScript, supporting such a feature? I could write my own compiler, but that would be a project in its own and take a while.
Also I am well aware of the async/await concept. Unfortunately I would have to declare all my functions up to the main() function as async in order to have it "block" at an await call.
I noticed a lot of people having that problem but there is no satisfying solution so far.