0

I have two classes named say A and B both has two methods named start and done. I create instance of both the classes.

var a = new A();
var b = new B();

I bind start event on b and done event to a.

a emits start so b.start is called, and b emits done so a.done is called. and this process continues until a.done decides and stops emitting start. It works fine till there is only one instance of B.

When I create two instances of B. b.start fires one extra time than it should.

and interestingly, when I emit done within a setTimeout() of zero ms, it works perfectly fine.

I am not sure if I explained it correctly. Please suggest what could be the cause. I tried lots of stuff which didn't give me a reason as why adding setTimeout helps.

Salman
  • 9,299
  • 6
  • 40
  • 73
  • 2
    JSFiddle? I suspect this will trace back to how you've implemented `start` and `done` ... but there's no code to look at – thefrontender May 20 '13 at 23:52
  • I will try and make a sample on fiddle. I just wanted to see if its a known problem. – Salman May 21 '13 at 04:34
  • Possible duplicate of [How to make an EventEmitter listen to another EventEmitter in Node.js?](https://stackoverflow.com/questions/26465358/how-to-make-an-eventemitter-listen-to-another-eventemitter-in-node-js) – Paul Sweatte Jun 15 '17 at 20:03

0 Answers0