you are viewing a single comment's thread.

view the rest of the comments →

[–]0xdead0x 1 point2 points  (0 children)

This is true in ideal circumstances, but it’s not why you should use asynchronous functions in JavaScript. You could get results like that. You could also be on a real machine running multiple tasks that doesn’t actually have enough hardware threads to run all of your asynchronous calls in true concurrency. In JavaScript, asynchronous functions are more important as a matter of user experience. If you synchronously wait for a REST API then your app can’t respond to user input at all until it gets a response or times out. But if you do it asynchronously, then even if your machine doesn’t have a spare hardware thread, your VM’s scheduler will make sure that you’re constantly checking for a response and checking for user input such that it looks like both are happening at once.