Trouble in Paradise

JavaScript was conceived to be a single-threaded language where asynchronous tasks are handled with events. When there are only a few potential events, event-based code is much simpler than multithreaded code. It’s conceptually elegant, and it eliminates the need to wrap up data in mutexes and semaphores to make it thread-safe. But when a number of events are expected, with state that needs to be carried from one event to the next, that simplicity often gives way to a code structure so terrifying that it’s been dubbed the Pyramid of Doom.

​ 
step1(​function​(result1) {
​ 
step2(​function​(result2) {
​ 
step3(​function​(result3) {
​ 
​// and so on...​
​ 
});
​ 
});
​ 
});

“I love async, ...

Get Async JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.