The event loop
Concurrency is the ability to execute two or more operations simultaneously. The JavaScript runtime execution takes place on a single thread, which means that we cannot achieve real concurrency.
The event loop follows a run-to-completion approach, which means that it will process a message from beginning to end before any other message is processed.
As we saw in Chapter 3, Mastering Asynchronous Programming, we can use the yield keyword and generators to pause the execution of a function.
Every time a function is invoked, a new message is added to the queue. If the stack is empty, the function is processed (the frames are added to the stack).
When all the frames have been added to the stack, the stack is cleared from top ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access