@spiff/forker

1.0.0 • Public • Published

forker

A system for managing inter process communication between generic interconnected modules. Its api is eventually going to be used in the purity browser.

Right now I'm going to call it a nodejs based userland microkernel framework.

usage

git clone https://github.com/purityapp/forker
cd forker
npm test

This will run an interactive nodejs console with the forker and manager objects pre-loaded. To run the example module, enter manager.spawn('example') a couple times. The example's ping message should be called a couple times, and the messages should be logged to the console.

documentation

API documentation is located in the docs foler.

example system

var system = new forker.System();

system.on('peer-found', function(peer) {
  peer.messages.ping(null, function(args) {
    console.log(args);
  });
});

system.messages.ping = function() {
  return {ping: 'pong'};
}

system.register('example', 'an example module');

After the forker.System object is created, a peer-found callback is set along with the ping message. When a new module recieves a peer, it is passed through the peer argument of the peer-found event. The recieving system can then inspect and call the peer's messages through the peer.messages object.

example manager

var manager = new forker.Manager();

manager.on('message', function(args) {
  args.to.process.send({from: args.from.process.pid, path: args.path, args: args.args});
});

Here the message event listener passes all messages to their intended recipient.

Readme

Keywords

none

Package Sidebar

Install

npm i @spiff/forker

Weekly Downloads

0

Version

1.0.0

License

GPL

Last publish

Collaborators

  • spiff