This module implements the 'distributed-eventemitter' API for the browser or single node processes.
Intended for non-distributed deployments or development.
Quick Start
var EventEmitter =require('process-eventemitter');
body:'Request/response feature is just awesome...'
},3000).then((response)=>{
if('sent'=== response){
console.log('email was sent!');
}
}).catch(console.log.bind());
Example using ES6 generators
"use strict";
constco=require('co');
co(function*(){
try{
let response =yieldevents.emitToOne('email.send',{
to:'kyberneees@gmail.com',
subject:'Hello Node.js',
body:'Request/response feature is just awesome...'
},3000);
if('sent'=== response){
console.log('email was sent!');
}
}catch(error){
console.log('error: '+ error);
}
});
Requirements
None
Installation
$ npm install process-eventemitter
Features
The same 'distributed-eventemitter' module API, but restricted to a single process and emitter instance.
The methods 'connect', 'disconnect' are just kept for compatibility, in case you want to make your code distributed later ;)
Internal events
events.on('connected',(emitterId)=>{
// triggered when the emitter has been connected
});
events.on('disconnected',(emitterId)=>{
// triggered when the emitter has been disconnected
});
events.on('error',(error)=>{
// triggered when an internal error occurs
}):
events.on('request',(event,request,raw)=>{
// triggered before invoke a listener using emitToOne feature
// request data filtering and modification is allowed