Oracle Magazine, July/August 2017
Database Developer OPEN SOURCE Figure 2 illustrates how asynchronous APIs work in Node js Now that you have a better understanding of how asynchronous work is handled in Node js lets talk about an issue newcomers sometimes run into the pyramid of doom The pyramid of doom aka callback hell results from the nature of how anonymous callback functions are often nested and indented to help keep the code maintainable Figure 2 How asynchronous Node js APIs work Evented Timers TCP UDP Thread Pool File I O DNS User Code Async API Calls Event Callback Queue Callback Functions Main Thread Heres a Node js example that makes three asynchronous API calls nested within each other to control the order of execution ORACLE MAGAZINE JULY AUGUST 2017 55 setTimeout function console log 1 three seconds after the start
You must have JavaScript enabled to view digital editions.