79657578

Date: 2025-06-08 06:37:20
Score: 0.5
Natty:
Report link

I did some reading and also dug through the Node.js source code. I now understand how the close() and on() functions work.

First, regarding the close() function, I had misunderstood that it adds a callback on the queue of the close callbacks phase. That's actually not true. In reality, the close() function uses a promise to close the file. In the callback that's executed when the promise resolves, the close event is emitted using process.nextTick().

As for the on() function, it simply adds a function to the list of handlers associated with a particular event.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: russell.price