Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Consider making all custom event callbacks asynchronous #108
For request/response event pairs, it's currently possible for replies to be either synchronous or asynchronous. Consider the following snippet.
this.trigger('cakeRequested'); this.on('cakeServed', eatCake);
Assuming a component
For the following example with the two calls flipped around (harder to read IMO),
this.on('cakeServed', eatCake); this.trigger('cakeRequested'); cleanPlate();
I'd recommend always ensuring callbacks are asynchronous. Wait until the next tick before calling listeners after an event is triggered, much like how Q provides the same guarantee for promises. See https://github.com/kriskowal/q/blob/master/q.js#L85
Couple of reasons why we don't do this:
You shouldn't need to switch away from using
If you look at the Q code, it tries a bunch of techniques to make this fast as possible (
Ah, that's interesting. Didn't know about the async hacks.
I know we wouldn't need to alter jquery code specifically but I meant that I think that Flight should not change how events work. Setting an event handler via Flight should act the same as setting an event handler directly with jquery. I think diverging would cause confusion.