GithubHelp home page GithubHelp logo

node-devents's Introduction

node-devents

A simple Redis-based distributed EventEmitter.

Installation

npm install devents

Usage

// MACHINE 1 (which also happens to be running redis)

var devents = require( 'devents' );

// create an event emitter that connects to redis running locally:

var emitter = new devents.EventEmitter();

// listen for 'some event' and print out the array it gets
emitter.on( 'some event', function( values ) {
    console.log( values );
});

// emit 'some event'
emitter.emit( 'some event', [ 1, 2, 3 ] );

Now, on another machine:

// MACHINE 2
var devents = require( 'devents' );

// create an event emitter that connects to redis running on MACHINE 1

var emitter = new devents.EventEmitter({
    host: 'machine1.company.com',
    port: 6379
});

// listen for 'some event' and print out the array it gets
emitter.on( 'some event', function( values ) {
    console.log( values );
});

Now, on MACHINE 1 you'd see:

[ 1, 2, 3 ]

But (amazingly) on MACHINE 2 you'd also see:

[ 1, 2, 3 ]

Caveats

A DistributedEventEmitter can only really handle JSON-encodable objects as arguments to the events.

That is, arguments are JSON-encoded before being sent to Redis. Functions on the object prototype will not work on the other side. And if your object causes JSON.stringify() to throw, that error is left uncaught.

Be sure to keep your arguments to basic, JSON-encodable types.

API

devents.DistributedEventEmitter inherits from events.EventEmitter and you should be able to use it exactly as you would expect, except that events are routed through Redis (if connected).

Note: When connected to a Redis server, all events are routed through the server which may affect their latency locally as one would expect.

TODO

  • Testing

Note on Patches/Pull Requests

  • They are very welcome.
  • Fork the project.
  • Make your feature addition or bug fix, preferably in a branch.
  • Send me a pull request.

License

node-devents is under the BSD license and you may use the code for any purpose you like with or without attribution.

node-devents's People

Contributors

andyburke avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

hyjin seitbekir

node-devents's Issues

Software License

Hi, I'd like to use node-devents in my project, what kind of license do you claim for node-devents?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.