When many async functions have been queued up, will their callbacks execute sequentially or concurrently?
-
3does this MDN documentation help? - specifically the "Run-to-completion" section, which I believe addresses your question almost directlyJaromanda X– Jaromanda X2017-08-19 03:50:16 +00:00Commented Aug 19, 2017 at 3:50
-
1This video explains the answer to your question: youtube.com/watch?v=8aGhZQkoFbQ0xcaff– 0xcaff2017-08-19 03:51:20 +00:00Commented Aug 19, 2017 at 3:51
-
Not sure why this question was tagged with ES6. The parallelism of (function) execution is a property of the runtime environment and has nothing to do with the language version.Bergi– Bergi2017-08-19 12:03:36 +00:00Commented Aug 19, 2017 at 12:03
-
ES6 is just the JS version I'm using. If the behaviour was up to the run time environment it would be chaos!? V8 vs spider monkey vs whatever. all doing different things--I don't think so. Doesn't the language spec specify the final behaviour irrespective of particular engine implementation?? (I'm not a JS developer so don't know if 'thread' management if different over past versions that's why I specified ES6).Ollie– Ollie2017-08-20 13:28:55 +00:00Commented Aug 20, 2017 at 13:28
Add a comment
|
1 Answer
They are run 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.