Event based actor model framework for game

NActor - Node.js actor model framework for game

The implementation is inspired by drama

It is an implementation of event-based actor model for node.js. It is designed for game backend service and may work with for sequential process of game events.

Of course it can be used for non-game service.

  • Easy to declare actor (Interface is similar to drama)
    • Automated binding of proxy interface
  • Sequential order of message execution
    • All the message sent to actor model is processed in sequential order
    • Actor's reply can work in async mode (e.g reply after database read/write)
    • Prevent the race condition of high concurrent write/read to a resource
    • Example usage: Judgement of game event sent from multiple players
  • Event based actor model
    • Running on main event loop
    • High performance
    • Non-restricted access to other resource
  • Support event emission from actor
  • Customizable error handling of uncaught exception in actor.
var nactor = require("nactor");
var actor ={
    // Declare your actor model through a object 
    hello : function(message) {
        // Actor method 
        return "Done";
// Intialize the actor 
// Ask to execute the hello() method. It will be called in next tick 

The constructs an actor model according to the declaration passed through argument. The return is a proxy of the actor which provides interface same as the declaration but the method will not be executed immediately. Instead, it is scheduled to run by the main event loop. The call is async.

The ask() is the standard method to invoke actor's method from proxy. Alternative method is "automated interface binding".

Instead of calling the ask() , you may execute the declared method by its name directly.


Remarks: You must call "init()" before execute any actor method. The interface will not be binded without "init()"

    console.log(reply); // "Done" 

In the previous example shows that the return from actor method will be passed to sender's callback. It is simple but not suitable for calls that depend on I/O resource. In this case , it should enable the async reply mechanism.

var nactor = require("nactor");
var actor = {
   // Alternative method of actor declaration 
   // It is the constructor and will be executed by 
   // init() immediately 
   // Remarks: It is not suggested to put async method here. 
   this.seq = 0; // Variables that can be shared for all methods. 
   this.timeout = options.timeout;
   return {
      // Declare the method  
      ping : function(data,async){
          async.enable(); // Enable async interface 
          },this.timeout); // Using "this" to access the variable declared 
// Intialize the actor 
   timeout : 200
   console.log(message); // Done! 

Beside ask() and reply(), actor may send information to sender through event emission.

var nactor = require("nactor");
var actor ={
    var self = this;
    this.handle = setInterval(function(){
    return {
        stop : function(){

As the actor method is not called directly, you can not catch the exception from actor in sender. Instead, you may call onUncaughtException() to add a listener for uncaught exception.


If an exception is uncaught , NActor will skip the processing message and handle the next. If you don't like the behaviour. You may stop the message execuation by calling ''action.stop()''


Remarks : The actor will no longer be usable after called ''action.stop()''