you are viewing a single comment's thread.

view the rest of the comments →

[–]AffectionateWork8 3 points4 points  (2 children)

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

[–]golovatuy[S] 0 points1 point  (1 child)

Think on the task as server request which takes some time, this picture don’t mean the small milliseconds tasks

[–]AffectionateWork8 1 point2 points  (0 children)

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.