ericgla / lemans

Virtual actor framework for node.js
MIT License
17 stars 1 forks source link
actor-model concurrency distributed-actors distributed-systems scalability virtual-actors

LeMans: Virtual actor framework for node.js

LeMans is a framework to writing distributed systems using virtual actors in JavaScript. It allows developers to write scalable applications while simplifying concurrency, state management and actor lifetime.

LeMans was inspired by the fine work of Microsoft Research on Orleans for the .NET framework. LeMans shares many of the same concepts and syntax as Orleans, but has a much different implementation due to the single-threaded nature of node and the use of isolated worker processes.

Basic Example

npm install --save lemans

const { Silo, GrainFactory, Grain } = require('lemans');

(async () => {
  const silo = new Silo({
    grains: {
      HelloGrain: class extends Grain {
        async sayHello() {
          return `Hello from HelloGrain with key ${this.key}`;
        }
      }
    }
  });

  await silo.start();

  if (silo.isWorker) {
    try {
      const grain = await GrainFactory.getGrain('HelloGrain', 'someGrainKey');
      console.log(await grain.sayHello());
    } catch (e) {
      console.error(e);
    }
  }
})();