<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: sleep() in JavaScript</title>
	<atom:link href="http://www.phpied.com/sleep-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpied.com/sleep-in-javascript/</link>
	<description>Stoyan&#039;s blog about &#60;a href=&#34;/category/xhtml&#34; class=&#34;tag-minor&#34;&#62;(x)html(5)&#60;/a&#62;, &#60;a href=&#34;/category/ajax&#34; class=&#34;tag-major&#34;&#62;ajax&#60;/a&#62;, &#60;a href=&#34;/category/bookmarklets&#34; class=&#34;tag-major&#34;&#62;bookmarklets&#60;/a&#62;, &#60;a href=&#34;/category/browsers&#34; class=&#34;tag-minor&#34;&#62;browsers&#60;/a&#62;, &#60;a href=&#34;/category/css&#34; class=&#34;tag-normal&#34;&#62;css&#60;/a&#62;, &#60;a href=&#34;/category/firebug&#34; class=&#34;tag-minor&#34;&#62;firebug&#60;/a&#62;, &#60;a href=&#34;/category/javascript&#34; class=&#34;tag-numero-uno&#34;&#62;javascript&#60;/a&#62;, &#60;a href=&#34;/category/json&#34; class=&#34;tag-normal&#34;&#62;json&#60;/a&#62;, &#60;a href=&#34;/category/mdb2&#34; class=&#34;tag-minor&#34;&#62;mdb2&#60;/a&#62;, &#60;a href=&#34;/category/mysql&#34; class=&#34;tag-normal&#34;&#62;mysql&#60;/a&#62;, &#60;a href=&#34;/category/pear&#34; class=&#34;tag-numero-uno&#34;&#62;pear&#60;/a&#62;, &#60;a href=&#34;/category/performance&#34; class=&#34;tag-major&#34;&#62;performance&#60;/a&#62;, &#60;a href=&#34;/category/php&#34; class=&#34;tag-numero-uno&#34;&#62;php&#60;/a&#62;, &#60;a href=&#34;/category/phpbb&#34; class=&#34;tag-major&#34;&#62;phpbb&#60;/a&#62;, &#60;a href=&#34;/category/tools&#34; class=&#34;tag-normal&#34;&#62;tools&#60;/a&#62;, &#60;a href=&#34;/category/yslow&#34; class=&#34;tag-minor&#34;&#62;yslow&#60;/a&#62;, &#60;a href=&#34;/category/yui&#34; class=&#34;tag-normal&#34;&#62;yui&#60;/a&#62;, &#60;a href=&#34;/category/writing&#34; class=&#34;tag-minor&#34;&#62;writing&#60;/a&#62;, &#60;a href=&#34;/category/music&#34; class=&#34;tag-major&#34;&#62;music&#60;/a&#62;,... &#60;a href=&#34;/category/life-and-everything&#34; class=&#34;tag-normal&#34;&#62;life and everything&#60;/a&#62;.</description>
	<lastBuildDate>Sat, 11 Feb 2012 14:07:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: I need to sleep, need to sleep, need some sleep, can't sleep, why can't I sleep, how to sleep better, lack of sleep</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-81580</link>
		<dc:creator>I need to sleep, need to sleep, need some sleep, can't sleep, why can't I sleep, how to sleep better, lack of sleep</dc:creator>
		<pubDate>Mon, 06 Feb 2012 17:25:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-81580</guid>
		<description>&lt;strong&gt;I need to sleep, need to sleep, need some sleep, can&#039;t sleep, why can&#039;t I sleep, how to sleep better, lack of sleep...&lt;/strong&gt;

[...]sleep() in JavaScript / Stoyan&#039;s phpied.com[...]...</description>
		<content:encoded><![CDATA[<p><strong>I need to sleep, need to sleep, need some sleep, can&#8217;t sleep, why can&#8217;t I sleep, how to sleep better, lack of sleep&#8230;</strong></p>
<p>[...]sleep() in JavaScript / Stoyan&#8217;s phpied.com[...]&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TSDarky</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-78097</link>
		<dc:creator>TSDarky</dc:creator>
		<pubDate>Thu, 30 Jun 2011 17:03:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-78097</guid>
		<description>Still Wondering::




	var t = new Date().getTime();
	var div = document.getElementById(&#039;a&#039;);
	function sleep() {
	
	 var s = new Date().getTime();
	
	 div.innerHTML += &quot;Old time &quot; + t +&quot;&quot;; 
	 div.innerHTML += &quot;New time &quot; + (s - t)+&quot;&quot;;
	
	 window.setTimeout(&quot;sleep();&quot;,1000);
	}
	
	sleep();
</description>
		<content:encoded><![CDATA[<p>Still Wondering::</p>
<p>	var t = new Date().getTime();<br />
	var div = document.getElementById(&#8216;a&#8217;);<br />
	function sleep() {</p>
<p>	 var s = new Date().getTime();</p>
<p>	 div.innerHTML += &#8220;Old time &#8221; + t +&#8221;";<br />
	 div.innerHTML += &#8220;New time &#8221; + (s &#8211; t)+&#8221;";</p>
<p>	 window.setTimeout(&#8220;sleep();&#8221;,1000);<br />
	}</p>
<p>	sleep();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GladiusMaximus</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-78089</link>
		<dc:creator>GladiusMaximus</dc:creator>
		<pubDate>Thu, 30 Jun 2011 03:00:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-78089</guid>
		<description>When your sleep function executes, it uses the CPU 100%. (stating the obvious). For example if you set a sleep function for two minutes, your clients browser won&#039;t be able to load the page completely for at least two minutes because it has to wait for your javascript function to finish itself.
Illustrated example on page three and four: http://www.google.com/googlebooks/chrome/big_02.html

There are two solutions:
1. Multi-threading. This means that your javascript can execute while the browser is loading the page at the same time. The browser still won&#039;t be able to execute the rest of your javascript until your sleep function is done. This is inferior to solution 2

2. Use setTimeout(foo, bar) and setInterval(foo, bar). setTimeout will execute foo after bar miliseconds AND continue with your javascript code while its waiting. setInterval will repeat foo every bar miliseconds until clearInterval() is called.
@Still Wondering, Use setInterval instead of setTimout
http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/
The deal with setTimout is that the statements after setTimeout are not delayed. ONLY the foo statement is delayed. This is good because it doesn&#039;t block up the rest of the flow. It just delays one statement. If you want more statements to be delayed (the entire thing maybe?), you can make an anonymous function

blah;
blah; //run normally
setTimout(function() {
    blahdelayed; //these statements are delayed 1000 seconds.
    blahdelayed;
}, 1000);</description>
		<content:encoded><![CDATA[<p>When your sleep function executes, it uses the CPU 100%. (stating the obvious). For example if you set a sleep function for two minutes, your clients browser won&#8217;t be able to load the page completely for at least two minutes because it has to wait for your javascript function to finish itself.<br />
Illustrated example on page three and four: <a href="http://www.google.com/googlebooks/chrome/big_02.html" rel="nofollow">http://www.google.com/googlebooks/chrome/big_02.html</a></p>
<p>There are two solutions:<br />
1. Multi-threading. This means that your javascript can execute while the browser is loading the page at the same time. The browser still won&#8217;t be able to execute the rest of your javascript until your sleep function is done. This is inferior to solution 2</p>
<p>2. Use setTimeout(foo, bar) and setInterval(foo, bar). setTimeout will execute foo after bar miliseconds AND continue with your javascript code while its waiting. setInterval will repeat foo every bar miliseconds until clearInterval() is called.<br />
@Still Wondering, Use setInterval instead of setTimout<br />
<a href="http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/" rel="nofollow">http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/</a><br />
The deal with setTimout is that the statements after setTimeout are not delayed. ONLY the foo statement is delayed. This is good because it doesn&#8217;t block up the rest of the flow. It just delays one statement. If you want more statements to be delayed (the entire thing maybe?), you can make an anonymous function</p>
<p>blah;<br />
blah; //run normally<br />
setTimout(function() {<br />
    blahdelayed; //these statements are delayed 1000 seconds.<br />
    blahdelayed;<br />
}, 1000);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Still Wondering</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-78009</link>
		<dc:creator>Still Wondering</dc:creator>
		<pubDate>Thu, 23 Jun 2011 11:05:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-78009</guid>
		<description>So... I have a loop that goes really fast, it changes a line in the page repeatedly, but it does it too fast to read.

It needs to wait a second each time before reprinting the updated text.

If I use a while loop with Date().getTime() to wait it clobbers the CPU and everything stops in other tabs/pages (eg music/video playing is affected).

If I use setTimeout(fn,1000) I only see the last one, because all the times are 1 second later, but still only a very short time apart - the time of a loop which still has not changed!

There must be a way to do this, or is Javascript really that lacking?</description>
		<content:encoded><![CDATA[<p>So&#8230; I have a loop that goes really fast, it changes a line in the page repeatedly, but it does it too fast to read.</p>
<p>It needs to wait a second each time before reprinting the updated text.</p>
<p>If I use a while loop with Date().getTime() to wait it clobbers the CPU and everything stops in other tabs/pages (eg music/video playing is affected).</p>
<p>If I use setTimeout(fn,1000) I only see the last one, because all the times are 1 second later, but still only a very short time apart &#8211; the time of a loop which still has not changed!</p>
<p>There must be a way to do this, or is Javascript really that lacking?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Movie Man</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-74066</link>
		<dc:creator>Movie Man</dc:creator>
		<pubDate>Mon, 20 Sep 2010 03:41:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-74066</guid>
		<description>Thanks, the original code posted here works great for my purpose. I don&#039;t care about syncro, asyncro, nor any other sink. Like one person implied above, maybe we should not “...actually do this unless you know what your doing.” Great idea - then we learn nothing.</description>
		<content:encoded><![CDATA[<p>Thanks, the original code posted here works great for my purpose. I don&#8217;t care about syncro, asyncro, nor any other sink. Like one person implied above, maybe we should not “&#8230;actually do this unless you know what your doing.” Great idea &#8211; then we learn nothing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: droope</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-72698</link>
		<dc:creator>droope</dc:creator>
		<pubDate>Mon, 19 Apr 2010 17:47:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-72698</guid>
		<description>This is my go @ it. I needed something quite different from what you needed.

/*
 * Sleep while condition == true
 * @param int interval - interval between every time sleep checks for condition (MS)
 * @param function/string condition - function that should return wether to continue looping or not. Beware of the scope of variables.
 * @param function/string onFalse - function to be executed when conditions return false. Expects a string like &quot;function()&quot; or a function.
*/
function sleep_while(interval, condition, onFalse) {
	if(eval(condition)) {
		setTimeout(&quot;sleep_while(&quot;+interval+&quot;, &quot;+ condition + &quot;, &quot; + onFalse + &quot;)&quot;, interval);
	} else {
		if(typeof( onFalse ) == &#039;string&#039;) {
			eval(onFalse);
		} else {
			onFalse();
		}
	}
}</description>
		<content:encoded><![CDATA[<p>This is my go @ it. I needed something quite different from what you needed.</p>
<p>/*<br />
 * Sleep while condition == true<br />
 * @param int interval &#8211; interval between every time sleep checks for condition (MS)<br />
 * @param function/string condition &#8211; function that should return wether to continue looping or not. Beware of the scope of variables.<br />
 * @param function/string onFalse &#8211; function to be executed when conditions return false. Expects a string like &#8220;function()&#8221; or a function.<br />
*/<br />
function sleep_while(interval, condition, onFalse) {<br />
	if(eval(condition)) {<br />
		setTimeout(&#8220;sleep_while(&#8220;+interval+&#8221;, &#8220;+ condition + &#8220;, &#8221; + onFalse + &#8220;)&#8221;, interval);<br />
	} else {<br />
		if(typeof( onFalse ) == &#8216;string&#8217;) {<br />
			eval(onFalse);<br />
		} else {<br />
			onFalse();<br />
		}<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-71769</link>
		<dc:creator>A</dc:creator>
		<pubDate>Tue, 10 Nov 2009 13:53:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-71769</guid>
		<description>The whole CPU!</description>
		<content:encoded><![CDATA[<p>The whole CPU!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: therealdealsince1982</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-71768</link>
		<dc:creator>therealdealsince1982</dc:creator>
		<pubDate>Tue, 10 Nov 2009 04:10:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-71768</guid>
		<description>I have searched/googled quite a few webpages on javascript sleep... and there is no answer if you want javascript to &quot;RUN, DELAY, RUN&quot;... what most people got was either, &quot;RUN, RUN(useless stuff), RUN&quot; or &quot;RUN, RUN + delayed RUN&quot;....

So I ate some burgers and got thinking:::
here is a solution that works... so you need to chop up your running codes...:::



DISPLAY


//javascript sleep by &quot;therealdealsince1982&quot;; copyrighted 2009
//setInterval
var i = 0;

function run() {
	//pieces of codes to run
	if (i==0){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ i +&quot; is ran&quot;; }
	if (i==1){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ i +&quot; is ran&quot;; }
	if (i==2){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ i +&quot; is ran&quot;; }
	if (i &gt;2){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ i +&quot; is ran&quot;; }
	if (i==5){document.getElementById(&quot;id1&quot;).innerHTML= &quot;all code segment finished running&quot;; clearInterval(t); } //end interval, stops run
	i++; //segment of code finished running, next...
}

t=setInterval(&quot;run()&quot;,1000);





//..............................



DISPLAY


//javascript sleep by &quot;therealdealsince1982&quot;; copyrighted 2009
//setTimeout
var i = 0;

function flow() {
	run(i);
	i++; //code segment finished running, increment i; can put elsewhere
	sleep(1000);
	if (i==5) {clearTimeout(t);} //stops flow, must be after sleep()
}

function run(segment) {
	//pieces of codes to run, can use switch statement
	if (segment==0){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ segment +&quot; is ran&quot;; }
	if (segment==1){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ segment +&quot; is ran&quot;; }
	if (segment==2){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ segment +&quot; is ran&quot;; }
	if (segment &gt;2){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ segment +&quot; is ran&quot;; }
}

function sleep(dur) {t=setTimeout(&quot;flow()&quot;,dur);} //starts flow control again after dur

flow(); //starts flow




//................................................


DISPLAY


//javascript sleep by &quot;therealdealsince1982&quot;; copyrighted 2009
//setTimeout, switch
var i = 0;

function flow() {
	switch(i)
	{
		case 0:
			run(i);
			sleep(1000);
			break;
		case 1:
			run(i);
			sleep(2000);
			break;
		case 5:
			run(i);
			clearTimeout(t); //stops flow
			break;
		default:
			run(i);
			sleep(3000);
			break;
	}
}

function run(segment) {
	//pieces of codes to run, can use switch statement
	if (segment==0){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ segment +&quot; is ran&quot;; }
	if (segment==1){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ segment +&quot; is ran&quot;; }
	if (segment==2){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ segment +&quot; is ran&quot;; }
	if (segment &gt;2){document.getElementById(&quot;id1&quot;).innerHTML= &quot;code segment &quot;+ segment +&quot; is ran&quot;; }
	i++; //current segment of code finished running, next...
}

function sleep(dur) {t=setTimeout(&quot;flow()&quot;,dur);} //starts flow control again after dur

flow(); //starts flow control for first time...


</description>
		<content:encoded><![CDATA[<p>I have searched/googled quite a few webpages on javascript sleep&#8230; and there is no answer if you want javascript to &#8220;RUN, DELAY, RUN&#8221;&#8230; what most people got was either, &#8220;RUN, RUN(useless stuff), RUN&#8221; or &#8220;RUN, RUN + delayed RUN&#8221;&#8230;.</p>
<p>So I ate some burgers and got thinking:::<br />
here is a solution that works&#8230; so you need to chop up your running codes&#8230;:::</p>
<p>DISPLAY</p>
<p>//javascript sleep by &#8220;therealdealsince1982&#8243;; copyrighted 2009<br />
//setInterval<br />
var i = 0;</p>
<p>function run() {<br />
	//pieces of codes to run<br />
	if (i==0){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ i +&#8221; is ran&#8221;; }<br />
	if (i==1){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ i +&#8221; is ran&#8221;; }<br />
	if (i==2){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ i +&#8221; is ran&#8221;; }<br />
	if (i &gt;2){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ i +&#8221; is ran&#8221;; }<br />
	if (i==5){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;all code segment finished running&#8221;; clearInterval(t); } //end interval, stops run<br />
	i++; //segment of code finished running, next&#8230;<br />
}</p>
<p>t=setInterval(&#8220;run()&#8221;,1000);</p>
<p>//&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;</p>
<p>DISPLAY</p>
<p>//javascript sleep by &#8220;therealdealsince1982&#8243;; copyrighted 2009<br />
//setTimeout<br />
var i = 0;</p>
<p>function flow() {<br />
	run(i);<br />
	i++; //code segment finished running, increment i; can put elsewhere<br />
	sleep(1000);<br />
	if (i==5) {clearTimeout(t);} //stops flow, must be after sleep()<br />
}</p>
<p>function run(segment) {<br />
	//pieces of codes to run, can use switch statement<br />
	if (segment==0){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ segment +&#8221; is ran&#8221;; }<br />
	if (segment==1){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ segment +&#8221; is ran&#8221;; }<br />
	if (segment==2){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ segment +&#8221; is ran&#8221;; }<br />
	if (segment &gt;2){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ segment +&#8221; is ran&#8221;; }<br />
}</p>
<p>function sleep(dur) {t=setTimeout(&#8220;flow()&#8221;,dur);} //starts flow control again after dur</p>
<p>flow(); //starts flow</p>
<p>//&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;</p>
<p>DISPLAY</p>
<p>//javascript sleep by &#8220;therealdealsince1982&#8243;; copyrighted 2009<br />
//setTimeout, switch<br />
var i = 0;</p>
<p>function flow() {<br />
	switch(i)<br />
	{<br />
		case 0:<br />
			run(i);<br />
			sleep(1000);<br />
			break;<br />
		case 1:<br />
			run(i);<br />
			sleep(2000);<br />
			break;<br />
		case 5:<br />
			run(i);<br />
			clearTimeout(t); //stops flow<br />
			break;<br />
		default:<br />
			run(i);<br />
			sleep(3000);<br />
			break;<br />
	}<br />
}</p>
<p>function run(segment) {<br />
	//pieces of codes to run, can use switch statement<br />
	if (segment==0){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ segment +&#8221; is ran&#8221;; }<br />
	if (segment==1){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ segment +&#8221; is ran&#8221;; }<br />
	if (segment==2){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ segment +&#8221; is ran&#8221;; }<br />
	if (segment &gt;2){document.getElementById(&#8220;id1&#8243;).innerHTML= &#8220;code segment &#8220;+ segment +&#8221; is ran&#8221;; }<br />
	i++; //current segment of code finished running, next&#8230;<br />
}</p>
<p>function sleep(dur) {t=setTimeout(&#8220;flow()&#8221;,dur);} //starts flow control again after dur</p>
<p>flow(); //starts flow control for first time&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Beck</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-71575</link>
		<dc:creator>Jamie Beck</dc:creator>
		<pubDate>Thu, 08 Oct 2009 04:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-71575</guid>
		<description>This site shows you a few different ways of creating a sleep function in JavaScript. And how each one affects the browser. 

http://www.devcheater.com

In the end the only thing that is cross browser safe is the setTimeout() and setInterval() functions.</description>
		<content:encoded><![CDATA[<p>This site shows you a few different ways of creating a sleep function in JavaScript. And how each one affects the browser. </p>
<p><a href="http://www.devcheater.com" rel="nofollow">http://www.devcheater.com</a></p>
<p>In the end the only thing that is cross browser safe is the setTimeout() and setInterval() functions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://www.phpied.com/sleep-in-javascript/#comment-71530</link>
		<dc:creator>Nathan</dc:creator>
		<pubDate>Thu, 24 Sep 2009 18:26:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/sleep-in-javascript/#comment-71530</guid>
		<description>Okay, so here&#039;s the deal with a real sleep vs. setTimeout scenario - I have functionality where under a certain condition I need to display a &quot;modal&quot; dialog box. Because of the complexity of what needs to be displayed inside this box, I cannot use &quot;alert()&quot;, &quot;confirm()&quot; or &quot;prompt()&quot;. However, I need the current JavaScript thread to halt (yes, I understand that JavaScript is single-threaded, although the inclusion of &quot;setTimeout&quot; and &quot;setInterval&quot; would suggest otherwise) until the box has received all the required input, and has been closed (identical to how &quot;alert()&quot;, &quot;confirm()&quot; and &quot;prompt()&quot; operate, so for the love of all that is holy, don&#039;t &quot;use setTimeout&quot; me - I&#039;ve explored using that for a week, and it&#039;s NOT a viable solution for me).

Frankly, the amount of quirky coding required to facilitate my needs using setTimeout would be arduous, and would require some truly screwed up process flow - all for the sake of avoiding a &quot;useless&quot; instruction such as &quot;sleep&quot;/&quot;wait&quot;/whatever. It&#039;s OBVIOUSLY something which is required, otherwise JavaScript wouldn&#039;t include &quot;alert()&quot;, &quot;confirm()&quot; and &quot;prompt()&quot;, functions which are designed to offer exactly this sort of functionality, but which are overly simplified.</description>
		<content:encoded><![CDATA[<p>Okay, so here&#8217;s the deal with a real sleep vs. setTimeout scenario &#8211; I have functionality where under a certain condition I need to display a &#8220;modal&#8221; dialog box. Because of the complexity of what needs to be displayed inside this box, I cannot use &#8220;alert()&#8221;, &#8220;confirm()&#8221; or &#8220;prompt()&#8221;. However, I need the current JavaScript thread to halt (yes, I understand that JavaScript is single-threaded, although the inclusion of &#8220;setTimeout&#8221; and &#8220;setInterval&#8221; would suggest otherwise) until the box has received all the required input, and has been closed (identical to how &#8220;alert()&#8221;, &#8220;confirm()&#8221; and &#8220;prompt()&#8221; operate, so for the love of all that is holy, don&#8217;t &#8220;use setTimeout&#8221; me &#8211; I&#8217;ve explored using that for a week, and it&#8217;s NOT a viable solution for me).</p>
<p>Frankly, the amount of quirky coding required to facilitate my needs using setTimeout would be arduous, and would require some truly screwed up process flow &#8211; all for the sake of avoiding a &#8220;useless&#8221; instruction such as &#8220;sleep&#8221;/&#8221;wait&#8221;/whatever. It&#8217;s OBVIOUSLY something which is required, otherwise JavaScript wouldn&#8217;t include &#8220;alert()&#8221;, &#8220;confirm()&#8221; and &#8220;prompt()&#8221;, functions which are designed to offer exactly this sort of functionality, but which are overly simplified.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

