I've got some very odd behaviour going on. I have the following JQuery:
myElement.fadeOut(100);
There is some kind of race condition going on, such that the element doesn't end up getting hidden. If I put a debugger on that line and step through the code, it works fine and the element fades out and gets hidden. Call it a Heisenbug.
My question is not about the race condition per se. I want to know how it is possible for this to happen given the nature of the JavaScript runtime. By my understanding the following predicates are true:
- fadeOut() is implemented by JQuery animate()
- animate() is implemented by a series of
setTimeout()
calls setTimeout()
schedules the execution of a function in a queue at some point in time- When events reach the start of the queue, the function is executed.
- There is only one event loop, which executes sequentially.
- At any given point in time, only one function / path through the callstack is executing.
Given that I am stepping through a function in my debugger, execution must be suspended and no other functions can be executing.
I cannot see how it is possible for a race condition to arise under these circumstances. Can you suggest how it is possible for execution to differ between debugged and non-debugged code?