Skip to content

Instantly share code, notes, and snippets.

@mariano-aguero
Created September 13, 2017 12:42
Show Gist options
  • Save mariano-aguero/cb5a11a1102fad3bac8932a285dc9cd2 to your computer and use it in GitHub Desktop.
Save mariano-aguero/cb5a11a1102fad3bac8932a285dc9cd2 to your computer and use it in GitHub Desktop.
Event bus
// Definition
const EventEmitter = require('events');
const emitter = new EventEmitter();
emitter.on('uncaughtException', function (err) {
console.error(err);
});
module.exports = emitter;
// Usage
let bus = require('../path/to/eventBus');
// Register event listener
bus.on('eventName', function () {
console.log('triggered!');
});
// Trigger the event somewhere else
bus.emit('eventName');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment