2

When many async functions have been queued up, will their callbacks execute sequentially or concurrently?

4
  • 3
    does this MDN documentation help? - specifically the "Run-to-completion" section, which I believe addresses your question almost directly Commented Aug 19, 2017 at 3:50
  • 1
    This video explains the answer to your question: youtube.com/watch?v=8aGhZQkoFbQ Commented 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. Commented 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). Commented Aug 20, 2017 at 13:28

1 Answer 1

2

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.

Dan Martensen offers a nice detailed writeup on the subject

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.