This should probably be moved off the dev list to the general jquery  
list.

There's a lot of misinformation in here about timers. I'd recommend  
people read John's discussion of timers:

http://ejohn.org/blog/how-javascript-timers-work/.

> I am not sure what you are asking for but from logical point of view  
> and generally speaking asynchronous calls do not guarantee order by  
> default


If we're only talking about JavaScript timers (setTimeout,  
setInterval), callback order is guaranteed to some extent. The html5  
draft spec says that callbacks that are eligible to execute are fired  
in the order queued. There are some corner cases that I'm not sure are  
spec'd, but common cases like two successive calls to setTimeout(fn,0)  
are guaranteed to be executed in the order queued. I haven't tried to  
test this in all browsers, but I haven't seen any violations of this

> var tid = setTimeout(function() {
>                                 clearTimeout(tid); delete tid ;
>                                 $(window).unbind('hashchange');
>                                 start();
>                         }, 500)

I think this is completely unnecessary. A timeout only executes once,  
so clearing it within it's callback should be completely unnecessary.  
Unless there's a real broken browser out there ... The draft spec says  
all intervals are canceled at unload, but I don't rely on unload, so I  
don't quite know what browsers do today in terms of subtle timing. I  
would think it unnecessary but maybe one can write code where order of  
callback firing is critical.

> I think asynchronous tests themselves should guarantee the order.

Two things are getting mixed here. qunit does not queue each  
individual test via setTimeout, so the order of test execution is not  
dependent upon the order of timer callback firing. But, repeating what  
I said above, if you do two setTimeout(fn,0) calls in your test, those  
callbacks should fire in the order you made the setTimeout calls. If  
they have different timeout values, things are less clear.

> Therefore: ordered firing of asynchronous events does not guarantee
> ordered finishing.

Async does not mean concurrent. JavaScript as implemented by most  
browsers is single-threaded. Only one callback is executing at a time.  
So when you do a setTimeout/setInterval call, regardless of what  
timeout you ask for, it cannot start until the current code, whether  
the main script or a callback, finishes. See John's blog article. So  
order of starting === order of finishing.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to