hoot

1.0.1 • Public • Published

NPM version Build Status Dependency Status

hoot

Inter-worker message-based communication in the node cluster. Based on this gist.

Install

$ npm install --save hoot

Usage

var hoot = require('hoot');
 
// in cluster master when creating workers
worker = cluster.fork();
hoot.registerWorker(worker);
 
// in worker
hoot.send('rainbow', { colors: 7 });
 
hoot.on('rainbow', function(data) {
  // all workers will see that
  console.log('Rainbow has ', data.colors, ' colors');
});

API

hoot.send(message, data)

Any worker can call send to broadcast message to all running workers. data can be passed along the message to the listener

hoot.on(message, listener)

Worker registers listener function for each message separately. listener receives message data as its argument.

hoot.registerWorker(worker)

Cluster master needs to call registerWorker for all workers that participate in message exchange.

License

MIT © Damian Krzeminski

/hoot/

    Package Sidebar

    Install

    npm i hoot

    Weekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • pirxpilot