3 ms·
In a real [event] system, events are dispatched sequentially. This seems off to me - if an explosion goes off, people's reactions will be simultaneous, not seq
by andreyf 18y ago
In a real [event] system, events are dispatched sequentially.
This seems off to me - if an explosion goes off, people's reactions will be simultaneous, not sequential. Similarly, in an actor/event model (which is what I'm thinking of) - when an event occurs, I would expect all objects affected by said event to respond simultaneously.
- Hexstream 18y agoI wonder if he was talking about: Let's say some code executes which fires event EA. Then we go execute handlers HA and HB for that event, in turn. But handler HA somehow triggers event EB which has a handler HC that depends on the state changed by HB. But HB hasn't fired yet because we're still in the HA handler. The illusion of simultaneousness is violated and we're fucked. The solution is to delay handling of events until all handlers for one "generation" of events have been called. edit: So maybe he meant "sequential" as in "not out-of-order".
- mpk 18y agoIf it's sequences you're looking for, try this technique I came up with a year or two ago, http://blog.mendix.com/?p=4 http://blog.mendix.com/?p=4 Doesn't use global variables and provides sequences that can be nested.
- andreyf 18y agoI'm not sure if I'm following... we've got: EA -> HA + HB HA -> EB -> HC With HC expecting HB to have run. My reaction would be "don't do that". If HC relies on HB completing, either put in a check in HC and keep trying until the environment is right (write a higher-order function if you're doing it often), or (better!) make your event system handle the logic you are trying to describe: HC is triggered when both HA and HB complete, like so: EA -> HA + HB HA -> EB HB -> EC EB + EC -> HC This is all trivial in JS, since handlers are just functions assigned to variables!