So, what I did was I went to my evil scientist lab, I thought, so, I know Node.js very well. I'm very familiar with its internals. I should be able to come up with a solution for this, right? And so, yeah. Remember when I made workers? Which I didn't make them all by myself. Obviously other people were involved. But like this statement, it doesn't feel entirely inaccurate. And, well, yeah. Anyway.
So, back then I obviously gave talks about that, too. And so, one of the slides from back then is like, the idea behind that is to embed Node.js into itself, to start a new Node.js instance, just like the main thread, except on a different operating system thread. And it turns out, like, if you think about it a bit more, you don't even need a separate thread for this. You can do it on the same thread. This is something that, like, I have thought about this in the past for various reasons. For example, testing systems like tap or might want to run pieces of code inside of somewhat isolated environments. I had conversations about that. I thought about what could we do about the with about XSync and similar functions in Node.js in the child processes. So, the way that these are implemented in Node is they have entirely separate implementations from the async methods. There's no good reason for that. And I think with this, we could even get down complexity inside of Node.js quite a bit if it ever ended up in Node.js.
So, the idea is instead of having separate threads, the main thread event loop still runs. It gives us its callback. And inside the callback or during startup code, we start a new event loop, a new Node.js instance with its own event loop on the same thread. And until we're done with that, nothing else on the main thread progresses. And, so, I came up, it's a pandemic. I was a bit bored during the holidays. So, this is a project that I came up with. And the idea is, like, this is all you need to actually achieve what we want. So, you create a synchronous worker. That's what I call it because it's kind of like a worker and that it starts a new Node.js instance, but it's also like no multi-threading involved. So, it's synchronous.
Comments