RE: Execute Last

"Moran Ben-David" <[email protected]> Tue, 21 Mar 2006 11:01:57 -0500
Newsgroups gmane.comp.web.dom.wdf
Message-ID <006c01c64d00$c84fce90$6401a8c0@short>
Much thanks to you, Ian.  I suppose you transposed my initial question to
one that asks whether setTimeout results parallel execution or not.  Your
answer being "not".

Given that, setTimeout is perfect for my case.  That is, it is essentially
like putting code at the end of the single execution thread.  I reran my
code and it works using 1ms.

Thanks for taking the time to answer and reformulate my example.  I greatly
appreciate it!

Moran

> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf
> Of Ian Petersen
> Sent: Tuesday, March 21, 2006 9:48 AM
> To: [email protected]
> Subject: Re: [wdf-dom] Execute Last
> 
> Hi Moran,
> 
> > Does anyone know of a good way to delay execution of a piece of code
> without
> > relying on time (as in setInterval and setTimeout)?
> 
> Can I ask why you're concerned about relying on time?
> 
> In my experience, all browsers run Javascript in a single thread,
> which means you can never have parallel execution, even if you use
> setTimeout.  So changing your code like this would do the trick:
> 
> var lastExecutors = []
> var timeoutID = null
> 
> function executeLast(o, f) {
>     lastExecutors.push([o, f])
> 
>     if(!timeoutID) {
>         timeoutID = setTimeout(cycleLastExecutors, 1);
>     }
> }
> 
> function cycleLastExecutors() {
>     timeoutID = null;
> 
>     var task;
> 
>     while(lastExecutors.length > 0) {
>         task = lastExecutors.shift();
> 
>         task[1].apply(task[0]);
>     }
> }
> 
> 
> With the above code, calling executeLast(foo, foo.last) will schedule
> a call to foo.last() to be run 1 millisecond after the current thread
> of execution terminates.  Is one millisecond too long for your
> application?
> 
> Ian
> 
> --
> Tired of pop-ups, security holes, and spyware?
> Try Firefox: http://www.getfirefox.com
> 
> 
> Unsubscribe
> [email protected]
> 
> List info
> http://www.quirksmode.org/dom/list.html
> Yahoo! Groups Links
> 
> 
> 
> 
> 




Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wdf-dom/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/