[Project_owners] Sleep or wait function for JavaScript

HJ van Rantwijk, MultiZilla bugs4hj at yahoo.com
Mon Oct 27 16:52:42 PDT 2008


joe ertaba wrote:
> Hi
> 
> I need to add sleep function in some procedure, I found some sleep function

Let me start by asking you something: "Why do you need this?"

Is it perhaps because some function (feature) in your code needs to wait 
for other functions (features) to complete/finish?

If yes, then please don't use setTimeout() nor nsITimer but use the 
nsIObserverService to notify your code, or fire some event when it is done.

Fixed timers/delays are never a good option, because your computer might 
be either slower or faster than mine, making one of us wait just because 
the other has a slower CPU/hardware.

Also, some people use recursive calls (too much) but they can be quiet 
harmful when things get broken, and stall the UI.

Cheers,
/HJ

-- 
I am HJ and I LIVE STRONG.
Supporter of the Lance Armstrong Foundation
http://www.livestrong.org


More information about the Project_owners mailing list