Node.js Interrupt Handlers – Implementing Interrupt Handlers in Node.js

ms-dosnode.js

I got started with programming back in the DOS days. One of my early projects involved overriding the keyboard interrupt service routine with my own. Now I'm trying out NodeJS to update myself, and I feel there is a similarity between the non-blocking design of NodeJS and my old experience with interrupt service routines (ISR). My guess is the similarity would be the keyboard ISR would wait for a key press input signal from the keyboard, while NodeJS waits for a web request. When the input arrives, both NodeJS and the ISR need to hurry to handle the request and say they're done in case a new input arrives. That is, there is a penalty for a CPU bound task slowing down the next web response or the next keyboard key input. Is this observation a reasonable understanding? I'm new to NodeJS so perhaps I'm missing an important difference or just incorrect in some fundamental way.

Best Answer

Sort of.

Interrupt Service Routines are really just hardware hooks so that the keyboard or other hardware device can make a subroutine call to the operating system while maintaining a degree of isolation. There's a lot more to it, of course, and if the method appears to be asynchronous, it's only because operating systems back then were capable of rudimentary task switching, or maybe even cooperative multitasking.

Node.JS's mechanism of operation is a bit different. Node.JS has an event loop that receives requests, each of which it assigns to a new thread under the covers. An async handler is registered to receive the eventual result of the requests. Everything happens at a much higher level of abstraction.

Related Topic