Distributed network-based event emitter for NodeJS
JavaScript
Switch branches/tags
Nothing to show
Permalink
Failed to load latest commit information.
test Merge branch 'master' of github.com:IndigoUnited/node-happening Feb 18, 2014
.editorconfig Update .editorconfig (made with screpto) Jan 2, 2016
.gitignore Tweak package Jun 21, 2013
.jshintrc Tweak package Jun 21, 2013
LICENSE
README.md Add license. Jun 22, 2013
example.js update One dependency and add example.js Feb 18, 2014
index.js Merge branch 'master' of github.com:IndigoUnited/node-happening Feb 18, 2014
package.json
test.js Create unit tests Feb 3, 2013
test1.js
test2.js update One dependency and add example.js Feb 18, 2014

README.md

happening

Distributed network-based event emitter for NodeJS.

NOTE: This is totally work in progress, and you should NOT rely on this for anything right now.

Installation

$ npm install happening

Note that happening depends on One, a distributed message queue based on ØMQ. So, if you're having a hard time installing, refer to its installation instructions.

Usage

You can use happening just like you would with any other event emitter. Here's a quick example:

var Happening = require('happening');

var happening = Happening.create(function (err) {
    if (err) {
        throw err;
    }

    happening.on('my_event', function (param1, param2) {
        console.log('got called with', param1, 'and', param2);
    });

    setInterval(function () {
        happening.emit('my_event', 'this', 'that');
    }, 500);
});

Considerations

Here's a list of things you should keep in mind when using happening.

Namespacing

Any emitter you create will join other emitters on the same network automatically, and act as one logical emitter. If you need multiple logical emitters, you can specify a namespace option:

var Happening = require('happening');

var happening = Happening.create({
        namespace: 'my_own_namespace'
    }, function (err) {
    if (err) {
        throw err;
    }

    happening.on('my_event', function (param1, param2) {
        console.log('got called with', param1, 'and', param2);
    });

    setInterval(function () {
        happening.emit('my_event', 'this', 'that');
    }, 500);
});

This emitter will only join other emitters that belong to the same namespace.

Using once()

If you add once() listeners on two separate nodes of the emitter, both will run once. Remember that in practice, you ran once() twice.

Cluster awareness

happening takes a few milliseconds to get up an running, which is why you have asynchronous create(), which will only call back once emitter has connected to at least one other node. If you want to raise the number of nodes it should wait for, you can pass a readyThreshold option, like so:

var Happening = require('happening');

var happening = Happening.create({
        readyThreshold: 3
    }, function (err) {
    if (err) {
        throw err;
    }

    console.log('found at least 3 nodes!');
});

License

Released under the MIT License.