<?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: Javascript Sleep Function</title>
	<atom:link href="http://coderscult.com/javascript-ajax/2009/02/05/javascript-sleep-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://coderscult.com/javascript-ajax/2009/02/05/javascript-sleep-function/</link>
	<description>Website development - HTML/XHTML, CSS, Javascript/AJAX, PHP, MySQL</description>
	<lastBuildDate>Fri, 14 May 2010 20:25:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: AGreenhill</title>
		<link>http://coderscult.com/javascript-ajax/2009/02/05/javascript-sleep-function/comment-page-1/#comment-220</link>
		<dc:creator>AGreenhill</dc:creator>
		<pubDate>Thu, 13 May 2010 18:59:29 +0000</pubDate>
		<guid isPermaLink="false">http://coderscult.com/?p=62#comment-220</guid>
		<description>This is not a solution for me... I&#039;m trying to avoid the IE script warning that occurs when a few million javascript operations occur... this can be done by setTimeout() but I seem to also require a true javascript sleep() function. Your jsleep() routine doesn&#039;t help since it simply chugs through a loop at lightning speed. Have you tried your jsleep() on IE for a few seconds? I have little doubt it craps out.</description>
		<content:encoded><![CDATA[<p>This is not a solution for me&#8230; I&#8217;m trying to avoid the IE script warning that occurs when a few million javascript operations occur&#8230; this can be done by setTimeout() but I seem to also require a true javascript sleep() function. Your jsleep() routine doesn&#8217;t help since it simply chugs through a loop at lightning speed. Have you tried your jsleep() on IE for a few seconds? I have little doubt it craps out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: therealdealsince1982</title>
		<link>http://coderscult.com/javascript-ajax/2009/02/05/javascript-sleep-function/comment-page-1/#comment-105</link>
		<dc:creator>therealdealsince1982</dc:creator>
		<pubDate>Tue, 10 Nov 2009 04:54:57 +0000</pubDate>
		<guid isPermaLink="false">http://coderscult.com/?p=62#comment-105</guid>
		<description>I have searched/googled quite a few webpages on javascript sleep/wait... 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... but you have to chop up your running codes...:::

replace &lt;.. with &lt; to run..
//.........................................
//example1:



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);





//....................................
//example2:



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




//.....................................
//example3:



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/wait&#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; but you have to chop up your running codes&#8230;:::</p>
<p>replace &lt;.. with &lt; to run..<br />
//&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..<br />
//example1:</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;&#8230;&#8230;<br />
//example2:</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;.<br />
//example3:</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: Al</title>
		<link>http://coderscult.com/javascript-ajax/2009/02/05/javascript-sleep-function/comment-page-1/#comment-103</link>
		<dc:creator>Al</dc:creator>
		<pubDate>Thu, 22 Oct 2009 19:31:01 +0000</pubDate>
		<guid isPermaLink="false">http://coderscult.com/?p=62#comment-103</guid>
		<description>This is a terrible implementation. The while loop will completely dominate the CPU and hang the browser until sleep is done. On Firefox, if you sleep for longer than 5 or 10 seconds, this will cause an ugly warning dialog because the browser will think the script is stuck in an infinite loop.

There is no JavaScript sleep() function. (Which I find to be a huge flaw with the langauge.) Instead, you should use setTimeout(). Google &quot;JavaScript sleep&quot; to find what other people have said on this topic, but a loop that polls the current time is NOT what you want.</description>
		<content:encoded><![CDATA[<p>This is a terrible implementation. The while loop will completely dominate the CPU and hang the browser until sleep is done. On Firefox, if you sleep for longer than 5 or 10 seconds, this will cause an ugly warning dialog because the browser will think the script is stuck in an infinite loop.</p>
<p>There is no JavaScript sleep() function. (Which I find to be a huge flaw with the langauge.) Instead, you should use setTimeout(). Google &#8220;JavaScript sleep&#8221; to find what other people have said on this topic, but a loop that polls the current time is NOT what you want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harish</title>
		<link>http://coderscult.com/javascript-ajax/2009/02/05/javascript-sleep-function/comment-page-1/#comment-98</link>
		<dc:creator>Harish</dc:creator>
		<pubDate>Tue, 22 Sep 2009 04:56:03 +0000</pubDate>
		<guid isPermaLink="false">http://coderscult.com/?p=62#comment-98</guid>
		<description>hi,

Thanks a lot for the code. I think lots of people are looking for this. Btw where do I find the class file for this?

regards,
Harish</description>
		<content:encoded><![CDATA[<p>hi,</p>
<p>Thanks a lot for the code. I think lots of people are looking for this. Btw where do I find the class file for this?</p>
<p>regards,<br />
Harish</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://coderscult.com/javascript-ajax/2009/02/05/javascript-sleep-function/comment-page-1/#comment-72</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Tue, 17 Feb 2009 14:51:21 +0000</pubDate>
		<guid isPermaLink="false">http://coderscult.com/?p=62#comment-72</guid>
		<description>Hi Mike,

I couldn&#039;t find anywhere to contact you so i thought i would do it through here. I know your blog is mainly on coding but noticed you posted some great tech posts such as the new mac video and thought a new video piece i am working on might be of interest to you. Its about a dysfunctional managers resistance to installing an ERP system. Although the video is really funny it does highlight some serious points.

http://www.k3scs.com/the-factory/

I thought it would point it out to you and if you have any feedback please let us know. Please also feel free to use the video.

Thanks

Mark</description>
		<content:encoded><![CDATA[<p>Hi Mike,</p>
<p>I couldn&#8217;t find anywhere to contact you so i thought i would do it through here. I know your blog is mainly on coding but noticed you posted some great tech posts such as the new mac video and thought a new video piece i am working on might be of interest to you. Its about a dysfunctional managers resistance to installing an ERP system. Although the video is really funny it does highlight some serious points.</p>
<p><a href="http://www.k3scs.com/the-factory/" rel="nofollow">http://www.k3scs.com/the-factory/</a></p>
<p>I thought it would point it out to you and if you have any feedback please let us know. Please also feel free to use the video.</p>
<p>Thanks</p>
<p>Mark</p>
]]></content:encoded>
	</item>
</channel>
</rss>
