javascript - Node.js listen and emmit events -
i have 2 classes , want 1 class subscribed other. this.
class one:
while(1){ if(true){ //emmit event }
class two:
//wait class 1 emmit data ,and start working data
my question is, there method, module.. can me implemented behavior?
use node's built-in eventemitter implement emitting , listening events in both clients.
example:
const eventemitter = require('events'); class myemitter extends eventemitter {} const myemitter = new myemitter(); myemitter.on('event', () => { console.log('an event occurred!'); }); myemitter.emit('event');
Comments
Post a Comment