https://github.com/pirxpilot/hoot
Inter-worker message-based communication in the node cluster.
https://github.com/pirxpilot/hoot
Last synced: 11 months ago
JSON representation
Inter-worker message-based communication in the node cluster.
- Host: GitHub
- URL: https://github.com/pirxpilot/hoot
- Owner: pirxpilot
- Created: 2015-05-02T21:40:47.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-02-23T06:56:26.000Z (over 9 years ago)
- Last Synced: 2025-03-17T10:03:46.565Z (over 1 year ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Dependency Status][gemnasium-image]][gemnasium-url]
# hoot
Inter-worker message-based communication in the node cluster.
Based on [this gist](https://gist.github.com/jpoehls/2232358).
## Install
```sh
$ npm install --save hoot
```
## Usage
```js
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](https://pirxpilot.me)
[npm-image]: https://img.shields.io/npm/v/hoot.svg
[npm-url]: https://npmjs.org/package/hoot
[travis-url]: https://travis-ci.org/pirxpilot/hoot
[travis-image]: https://img.shields.io/travis/pirxpilot/hoot.svg
[gemnasium-image]: https://img.shields.io/gemnasium/pirxpilot/hoot.svg
[gemnasium-url]: https://gemnasium.com/pirxpilot/hoot