1

Imagine I have multiple routes

/login
/register
/verify

And it happens that /login route has an async function somewhere

What if for example, during the await of an async function in /login (because an user is logging in) , another user is using at the same time the route /verify . Will this user experience a delay because of the await? Or does node use some sort of multithreading to avoid the issue? Or should I simply use a promise and a .then instead?

mouchin777
  • 1,428
  • 1
  • 31
  • 59
  • 1
    As much as I know node is multithreading and this is the main power of using as API, is "built-in" – dloeda Jan 29 '20 at 11:10
  • @dloeda so I suppose that await scope is limited to the async function, right? – mouchin777 Jan 29 '20 at 11:11
  • 1
    Yes, is limited to that "thread" – dloeda Jan 29 '20 at 11:11
  • 2
    @dloeda Node doesn't simply automatically multi-thread, no. You *can* multi-thread, but you need to do so explicitly, because your code needs to ensure it'll work correctly under multiple threads. The simple answer to the question is that no, while a truly `async` function is being awaited, other requests are *not* blocked. They will interleave as async tasks on the single thread. This is easy to test with awaiting a `setTimeout(100000)` or such… – deceze Jan 29 '20 at 11:14

0 Answers0