Are there significant differences between the Chrome browser event loop versus the node event loop?

前端 未结 3 828
梦谈多话
梦谈多话 2021-01-30 06:59

Philip Roberts does a brilliant job explaining the browser event loop here providing a clear explanation between the call stack, event loop, task queue, and then \"outside\" thr

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-30 07:54

    ...when I make a call using Node's file and web i/o libraries, these are things that happen outside the stack whose callbacks are queued in a task queue?

    Yes, absolutely; they're asynchronous just like Ajax and setTimeout are asynchronous. They perform some operation outside of the call stack, and when they've finished that operation, they add an event to the queue to be processed by the event loop.

    Node's API provides a kind of asynchronous no-op, setImmediate. For that function, the "some operation" I've mention above is "do nothing", after which an item is immediately added to the end of the event queue.

    There is a more powerful process.nextTick which adds an event to the front of the event queue, effectively cutting in line and making all other queued events wait. If called recursively, this can cause prolonged delay for other events (until reaching maxTickDepth).

提交回复
热议问题