Independent actors
A program is built with self contained code segments describing what to do when a message is received in a mailbox which is processed FIFO
This was my Final Year Project for my B.Sc in Computing Science. I felt like Node.js and Browser runtimes suffered from its Single Threaded Event Loop when compared to multithreaded languages like Go or Java. I wanted make it possible for devs to fill this gap while also playing on JavaScript's strengths on it being built for the web, and its concurrency model enabled by the Promise system.
This project enables JavaScript to be run with distributed parallelism through embracing the use of Actor Network Theory, which is heavily employed by Erlang and Elixir. Because why shouldn't your fridge, TV, phone and PC work together on calculating the next prime number?
A program is built with self contained code segments describing what to do when a message is received in a mailbox which is processed FIFO
JavaScript's runtime is naturally concurrent, so actors processing messages can safely suspend by using promises for the next actor to take the thread
The library harnesses Node Js Child Processes and Web Workers to bring parallel threads, allowing multiple actors to process their message at the same time
JavaScript is built for the web, so with a central orchestration server it can coordinate a GPU powered server with your home fridge to coordinate on the same goal
Single instance example
import actors from 'nodeactors.js';
const { init, closeConnection, spawn, spawnRemote, terminate, send } = actors;
// Define the behaviour of the two actors.
const pingPongBehaviour = (state, message, self) => {
console.log(message.val);
if (!(message.val - 1 < 0))
send(message.replyTo, { val: message.val - 1, replyTo: self });
};
// Spawn actors
const ping = spawn({}, pingPongBehaviour);
const pong = spawn({}, pingPongBehaviour);
// Send ping a message. Output will be decrementing values from 5 to 0
send(ping, { replyTo: pong, val: 5 });Distributed Parallel Example
