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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -