I have been trying to understand the way ActionScript's events are implemented, but I'm stuck.
I know that AS is single threaded, which means that only one event handler will be executing at a time, and also means that handlers will be executed in a deterministic order*.
For example, consider the following code:
1: var x = {executed: false};
2: foo.addEventListener("execute", function(){ x.executed = true; });
3: foo.dispatchEvent(new Event("execute"));
4: assert(x.executed);
If ActionScript was multi-threaded, it would be possible that the assertion on line 4 could fail sometimes and succeed others.
But since AS is not multi-threaded, it stands to reason that the assertion will either always fail² or always succeed³. Or, in other words, events will be handled in a deterministic way.
So, is this assumption (that events hare handled deterministically) correct? Does Adobe provide any definitive documentation on the matter?
Note: I am only concerned here with events dispatched by dispatchEvent
– I realize that "externally dispatched" events (network traffic, user input, timers ticking, etc) behave differently.
*: with the exception, of course, for events triggered by nondeterministic things like user input or network traffic.
²: it would always fail if, for example, if the event handling algorithm was: "push new events onto a stack, then continuously pop the top event off the stack, execute it until it terminates, then go on to the next event".
³: it would always succeed if events dispatched by dispatchEvent
were handled as soon as they were dispatched.