[thelist] Javascript - order of code execution

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Wed May 11 08:25:33 CDT 2005



works fyi.

So imho, assigning the render function to a separate thread via
settimeout is adequate and the given timeout amount is unimportant.

I think in the first case the GUI update of the rendering engine and
the script execution are queued on the same thread, and the GUI render
waits for the script to finish.

However in the second case (with timeout) a separate thread is
spawned, for the render engine, so that both operations can occur
syncronously. Thus even if the large operation takes 10 seconds, the
"Calculating..." label will be shown as soon as the spawned thread
finds a free cpu cycle, which will occur in 10-30 milliseconds

However that's my view from a java-developer's perspective. I've not
read how things actually happen, it's just my intelligent deduction.

any opinions?


On 5/11/05, Edwin Martin <edwin at bitstorm.org> wrote:
> Alex wrote:
> > I am hoping there are some Javascript gurus out there that are able to
> > answer my seemingly simple, yet frustrating, problem.
> This is normal behaviour. The user interface is updated
> *after* the JavaScript has finished.
> The way to work around this is to split your code in two
> parts: the first part where you update the user interface
> and the second part, where you do the calculations.
> The you call the second part with setTimeout().
> Something like this:
> function start() {
>        // update interface here
>        setTimeout( 'calculation()', 100 )
> }
> function calculation() {
>        // Do your calculation here
> }
> Edwin Martin
> --
> http://www.bitstorm.org/edwin/en/
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !

More information about the thelist mailing list