Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 29-06-2009
Member
 
Join Date: Feb 2009
Posts: 14
JavaScript Sleep Function

Hello , Can you Tell me what is sleep Funtion in Javascript , and How to Implement Sleep Function , And what are other Necessary Constraint Related to it , Please Help Thanks in advance
Reply With Quote
  #2  
Old 29-06-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: JavaScript Sleep Function

Check the implementation of the "sleep" function in javascript.

Code:
function sleep(timeout) { 
var loop = true; 
var current = new Date(); 
var now; 
var cTimestamp = current.getTime(); 

while(loop) { 
now = new Date(); 
nTimestamp = now.getTime(); 

if(nTimestamp - cTimestamp > timeout) { 
loop = false; 
} 
} 

}
Reply With Quote
  #3  
Old 29-06-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: JavaScript Sleep Function

the only possible solution seems to be currently going through the narrative javascript compiler that will compile a code that will allow us to make pauses in it.

Quote:
function sleep (millis) (
var notify = new EventNotifier ();
setTimeout (notifier, millis);
notified. wait -> ();
)
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 29-06-2009
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: JavaScript Sleep Function

the Truth is the pause in javascript is not recommended beyond the fact that it is not really feasible. I just wrote this article because I needed to test the function I created evalglobal under the engine KHTML (Konquero, Safari ..). I thought going through setTimeout departure, which was a mistake. try this on any engine, the result is impressive:

Code:
test = undefined; 
setTimeout ( "var test = function () (alert (" test is a function ");) ', 10); 
var Start = (new Date ()). GetTime (); 
while (typeof test! = 'function') ( 
if (((new Date ()). GetTime () - start)> 6000) ( 
alert ( 'test definitely undefined'); 
break; 
) 
) 
if (typeof test == 'function') test ();
The execution priority is given to the current scope which leaves the function sent to setTimeout.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "JavaScript Sleep Function"
Thread Thread Starter Forum Replies Last Post
Passing XSL value to javascript function Steadfast Software Development 6 13-05-2010 11:51 PM
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 10:44 PM
Eval function in javascript Solaris Software Development 5 02-03-2010 05:59 PM
Javascript isNull function Chrisch Software Development 3 11-11-2009 02:51 PM
JavaScript function help suseman Software Development 3 26-05-2009 05:11 AM


All times are GMT +5.5. The time now is 08:06 PM.