user1968030
user1968030

Reputation:

Execute callback in node

I know Node.js is single threaded and uses asynchronous operations for I/O.

whenever Node.js is not executing code, the runtime checks for events (more accurately it uses platform-native API’s which allow it to be activated when events occur). Whenever control is passed to the Node.js runtime, another event can be processed. The event could be from an HTTP client connection, or perhaps from a file read.

How many callbacks can execute at the same time in Node?

Upvotes: 0

Views: 88

Answers (3)

shmuli
shmuli

Reputation: 5192

There can only be one callback firing at the same time.

Upvotes: 0

hexacyanide
hexacyanide

Reputation: 91769

Node runs on an event loop, which you can think of as a queue of callbacks to be processed each tick of the event loop. Therefore, callbacks are executed one by one since the loop is on a single thread, which is what makes functions such as process.nextTick() available.

Upvotes: 1

JohnnyHK
JohnnyHK

Reputation: 312075

All of your own code executes in a single thread, so only one callback is actively running at a time, and it will continue to run until it calls an async function or completes.

Upvotes: 1

Related Questions