I am trying to come up with a minimal example of what is known as callback hell in JavaScript (so this would be a bad code review I guess). This is what I have so far, and I would like it to also run without making external requests. I'm not sure if that's possible or if this example is hellish enough (do I need to introduce errors,arguments in the callbacks etc.). The point I am trying to make is that it is hard to tell when things happen.
I am aware of another hellish construct called the Pyramid of Doom, in my mind and from what I've read that could be a different problem, i.e. while order is somehow clear, nesting makes it hard to troubleshoot,maintain and write.
function one() {
setTimeout(function() {
console.log('1. First thing calling Second thing');
two();
}, 2000);
};
function two() {
console.log('2. Second thing');
}
function three() {
setTimeout(function() {
console.log('3. Third thing calling fourth thing');
four();
}, 1000);
}
function four() {
console.log('4. Fourth thing');
}
one();
three();
// "3. Third thing calling fourth thing"
// "4. Fourth thing"
// "1. First thing calling Second thing"
// "2. Second thing"