-1

I'm at a bit of a loss here. I have an issue that I think may be due to mouse events taking precedence. I have a function f being invoked on mouse clicks - f does some work, then invokes another function g. Is it even possible that f runs, then another click happens - invoking f again - and then g is executed?

If my phrasing is hard to understand, I'll try to show what I think may be happening:

    click1 -----       /-----------\
                \     /             \
                  f --      f--      g    g
                           /   \         /
      click2 ------------ /     \--------

 |---------------- timeline----------------------|

I can say for certain the issue only arises (out of ~50 slow and ~50 quick double-clicks) when clicking twice in very quick succession (and not always even then). I realize my figure may confuse more than it clarifies, but I'm not sure how else to communicate my thoughts. Any input is greatly appreciated!

ketan
  • 19,129
  • 42
  • 60
  • 98
EvenLisle
  • 4,672
  • 3
  • 24
  • 47
  • I don't think you described the issue at all. Anyway there's no race condition happening on events, all code get executed period. – BotMaster Jan 15 '16 at 13:10
  • I intentionally didn't describe the issue because if this is not the reason, then it could be anywhere in a pretty large codebase (wouldn't be able to summarize everything that goes on in a single question). So you're certain that a mouse click event could not interrupt running code? Do you have any references to back up your claim? P.S.: I'm sorry if I'm coming across as difficult, I just want to be certain so that I may move on to investigating other possibilities. – EvenLisle Jan 15 '16 at 13:39
  • 1
    Have you logged the calls to `f` and `g` to see if the order is what you expect? – Aaron Beall Jan 15 '16 at 19:34

1 Answers1

2

AS3 is a single threaded code execution environment which will execute all relevant code as it present itself. if a click triggers the execution of a chain of methods, all those methods will run before any other code can be executed again. As a result there cannot be a race condition in the code execution of AS3 code because of it single threaded nature.

All events in AS3 are not a special case in that regard, when their listener triggers all its code is executed the same way and no other code can be executed until it's done.

Special cases are:

  • You can suspend the execution by using timers and such so execution of code will happen at a later time. In that case there's no guaranty the triggering of those timers will be in sync with their starting order.

  • Executing asynchronous command (like loading something), in that case there's no guaranty loading operations will happen in order either.

But those special cases are not violating the execution of code principle in AS3, all code execute in one thread so their cannot be overlapping of any kind.

BotMaster
  • 2,233
  • 1
  • 13
  • 16