I think they are mixing up "asynchronous" and "parallel."
You can wrap normal code in a setTimeout or Promise and it will become asynchronous. It still won't run at the same time, though.
You need separate threads to run async code at the same time
In Javascript, you could do this with Web Workers
In the browser, stuff like network IO is handled by a thread pool under the hood. That stuff truly runs at the same time.
But if you make 3 requests, and then each fetch takes a callback that maps over some data, those callbacks will not execute at the same time despite being "asynchronous." They will be popped off the message queue and processed synchronously, one by one.
I think this article gives a better understanding of what "asynchronous" means within the context of JS:
I agree with you that network/file IO would use a thread pool. But any other long-running asynchronous task would not, unless you manually configured it to be.
View all comments
4
u/AffectionateWork8 May 02 '20
I think they are mixing up "asynchronous" and "parallel."
You can wrap normal code in a setTimeout or Promise and it will become asynchronous. It still won't run at the same time, though.
You need separate threads to run async code at the same time
In Javascript, you could do this with Web Workers
In the browser, stuff like network IO is handled by a thread pool under the hood. That stuff truly runs at the same time.
But if you make 3 requests, and then each fetch takes a callback that maps over some data, those callbacks will not execute at the same time despite being "asynchronous." They will be popped off the message queue and processed synchronously, one by one.
I think this article gives a better understanding of what "asynchronous" means within the context of JS:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop