tags:

views:

46

answers:

3

Hi,

I know that flex does not support multi threading however, I would like to clear a doubt. I have two events that call a same function. Suppose the two events occur at the same instant (or in quick succession) will the handler be called twice, one after the other or there is a chance that if the handler function is taking too much time to execute the same handler can start executing simultaneously.

Thnanks

+1  A: 

The handler will be called twice, once with each event. The second call (and essentially, the entire app) will be blocked until the first call has returned.

Here's a nice overview of the event cycle--doesn't specifically address your question, but it's a nice broad picture.

And you can't go wrong with the elastic racetrack.

Michael Brewer-Davis
Yes, the handler will be called twice for sure. The question is will the handler be called for the second time only after the first execution has ended or is there a possibility (if the first execution is taking time) that the execution of the handler second time starts before the execution of the first hand ended.
Gaurav
Yes that was the answer I was looking for, I didnt' want the two calls to be simultaneous. I am actually executing some code in the handler and if the code executes fine, I set a flag to ensure that the second call does not execute the same code again. This code would have created a bug if before setting the flag (which is done in the end) the second execution starts.
Gaurav
A: 

Yes it will always get called twice. Yes one of the two calls will complete before the other is started. Unless you are doing something like dispatching an event in the handler for another handler to work on, then it all goes out the window! Even then I believe the first call will complete, but the event it dispatched may get resolved before the second call happens, sometimes....sorta. ;) YMMV

mezmo
A: 

If you didn't know, using PixelBender, Flex can do multi-threading. Other than for graphics, you can make use of pixelbender to do mathematical functions quickly which you may find a use for :)

adamk