The fact that all the CPU work in a node.js process is done by a single thread continues to amaze me. But, considering node.js cluster API, it all makes so much sense! Having just one thread per CPU core is the "ideal situation", which barely any piece of software ever achieves. I remember good example on this topic from "CLR via C#" book — it's about Windows native File Open dialog, which creates tens (!) of new threads when it opens up.
So it's all good, but we pay the price for that in the amount of asynchrony we put into the source code. There are good libraries out there, which help in taming this additional complexity, but they usually don't focus on decreasing perceptual complexity of the source code. This is what I tried to do in the tiny node.js library, called "parellel-io". It helps in situations, when you have multiple I/O operations, which you want to run in parallel and then conveniently process their results all at once. Following is an example of it's use:
So it's all good, but we pay the price for that in the amount of asynchrony we put into the source code. There are good libraries out there, which help in taming this additional complexity, but they usually don't focus on decreasing perceptual complexity of the source code. This is what I tried to do in the tiny node.js library, called "parellel-io". It helps in situations, when you have multiple I/O operations, which you want to run in parallel and then conveniently process their results all at once. Following is an example of it's use:
Comments