Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is Web API:S Fetch() parallell or async?

I’m having trouble finding the answer to this.
When we call fetch(), is the browser opening a new thread or is the call just put in the microqueue?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The answer is sort of "both":

  • The network request itself is processed in parallel with anything else happening on your JavaScript thread, not on the JavaScript thread. (In all major browsers.)

  • When the network request is complete, a promise reaction (fulfillment or rejection) is queued to be picked up by the JavaScript thread when it’s next checking the relevant queue. (I think what happens is that the browser queues a task that settles the promise, which in turn queues any relevant promise reactions in the microtask queue. The details don’t really matter, though; fundamentally, once the network request is complete, a task/microtask is queued somewhere for any promise reactions that need to happen, and picked up by the JavaScript thread like other tasks/microtasks.)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading