Assume I have these two functions:
function complex() {
setTimeout(function() {
console.log('complex setTimeout');
}, 1000); // assume this value is random
function subFun() {
console.log('complex subFun');
setTimeout(function() {
console.log('complex subFunction setTimeout');
}, 2000); // assume this value is random
}
subFun();
}
function simple() {
console.log('simple');
}
Assume that I didn't write them - they are third party. Now I want to call them synchronously and get:
complex subFun
complex setTimeout
complex subFunction setTimeout
simple
The problem is, I can't use callbacks (third party functions). I also can't use promises or events (the same reason). I can't use async
and step
modules, because of functions arity. How the hell can I call simple()
after complex()
(and all nested sub-functions) synchronously? And do JavaScript sux? :)