DEV Community

Introducing Nexus.js: A multi-threaded JavaScript run-time

Abdullah Ali on December 09, 2017

First of all, I recommend reading the old series if you're not familiar with this project. If you don't want to read all of that, no worries! I got...
Collapse
 
spyke profile image
spyke •
let count = 0;

acceptor.on('connection', (socket, endpoint) => {
  const connId = count++;

How does it work? If event listeners run on parallel threads, there will be a race condition in the increment without synchronization.

Collapse
 
voodooattack profile image
Abdullah Ali •

Hi! Concurrent access to variables does not corrupt them or cause a race condition. All variables behave atomically in Nexus.

Read more here: nexusjs.com/architecture/

Collapse
 
spyke profile image
spyke • • Edited

So, in this particular example

When two different execution contexts that share a closure variable are entered in parallel, one will acquire a lock

means that a listener will lock on parent closure right at the start of the function till its end? Or it will lock only from the time of identifier resolution for count to finishing its value reading?

Thread Thread
 
voodooattack profile image
Abdullah Ali •

It will only lock upon access to the variable and then it will release the lock as soon as it is done.

Thread Thread
 
spyke profile image
spyke •

Thank you.

Thread Thread
 
voodooattack profile image
Abdullah Ali •

You’re welcome :)

Collapse
 
brandonros profile image
Brandon Ros •

Post a graph comparing a similar node.js application (and maybe even Java/Haskell/whatever people compare these days) and show how this handles concurrent requests in a more performant fashion?

Collapse
 
voodooattack profile image
Abdullah Ali •

That’s all planned. :)

I’m just waiting till Nexus is a little more mature before making big comparisons.

Collapse
 
trusktr profile image
Joe Pea •

A simple test comparing simple things like many setTimeout operations compared to Node.js would be nice, before the more complicated tests.

Collapse
 
sreejithms profile image
Sreejith • • Edited

Few newbie questions.
Where can I use this? inside a node server? or can I use it on the clientside?
From the docs it says multi-threaded JavaScript run-time, so is it like V8?
Can we make use of WebAssembly and create a library to support multi-threading much more effectively?

Collapse
 
voodooattack profile image
Abdullah Ali •

Hi! You can only use Nexus on the server right now. It's a stand-alone environment and doesn't require a Node.js installation.

It's not based on V8, it's based on JSC.

I just introduced WebAssembly support to the repo. So yes, you can use multi-threading with WebAssembly now. Although I'm still ironing out the details.

Collapse
 
blonkm profile image
Michiel van der Blonk •

Incredible!

Collapse
 
voodooattack profile image
Abdullah Ali •

Thank you. :)

Collapse
 
vaibhav93 profile image
Vaibhav Bansal •

This sounds amazing. Can you do an article comparing it with napajs ? That'll be great

Collapse
 
voodooattack profile image
Abdullah Ali •

I certainly plan to do that at some point, once I get the code to a more stable state. :)

Collapse
 
jtenner profile image
jtenner •

Is there a location for chat? Like discord, or slack where people can chat about it?

Collapse
 
voodooattack profile image
Abdullah Ali •

There is a Gitter channel here: gitter.im/voodooattack/nexusjs

Collapse
 
leecen profile image
leecen •

You can support commonJs like Node module Suorce Code

Collapse
 
voodooattack profile image
Abdullah Ali •

Even Node itself is phasing away from CommonJS, why would I want to repeat its mistakes?

Collapse
 
trusktr profile image
Joe Pea •

This is a nice project! Any news on this?