Naman N.’s Post

#JS_Core (3 of 7) How can #Single_Threaded_Language handle 5 API calls "simultaneously" ?? The truth is, it doesn't. Our single threaded language JavaScript is not a worker but a coordinator Here is what happens under the hood when you trigger an async task - > JS hands off tasks (Timers, Network calls, File I/O) to the environment (Browser APIs or Libuv in Node.js). > It keeps executing your synchronous code immediately. The main thread is never blocked by the "waiting." > Once the environment finishes the task, the Event Loop pushes the result back into the execution queue to be processed. To orchestrate this chaos, we have modern Promise methods as: > .all : Waits for all to succeed. If one fails, the whole operation rejects. > .allSettled : It Waits for everything to finish, regardless of success or failure. > .any : It returns the first promise that succeeds (unless they all fail). > .race : It returns the result of the very first promise to settle #JavaScript #NodeJS #EventLoop #AsyncAwait #SoftwareEngineering #WebDev

  • diagram

To view or add a comment, sign in

Explore content categories