Ollie Ollie - 6 months ago 57
Javascript Question

Javascript (ES6) asynchronous callback execution

When a bunch of async functions have been queued up (e.g., XHRHttpRequest) and their callbacks are being called; are the callbacks themselves run sequentially in from some sort of que? Or do they get interleaved (run concurrently).


Answer Source

They are ran sequentially, even though they may be queued up in an asynchronous manner.

Events are triggered in a multi-threaded area of the browser called Web APIs. Following an event (e.g. XHR request) being triggered asynchronously, an event loop synchronously selects the event's callback onto JavaScript’s single-threaded call stack to be executed.

Dan Martensen offers a nice detailed writeup on the subject

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download