Results 1 to 4 of 4

Thread: JavaScript Sleep Function

  1. #1
    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

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    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; 
    } 
    } 
    
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    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.

    function sleep (millis) (
    var notify = new EventNotifier ();
    setTimeout (notifier, millis);
    notified. wait -> ();
    )

  4. #4
    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.

Similar Threads

  1. Passing XSL value to javascript function
    By Steadfast in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 11:51 PM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Eval function in javascript
    By Solaris in forum Software Development
    Replies: 5
    Last Post: 02-03-2010, 05:59 PM
  4. Javascript isNull function
    By Chrisch in forum Software Development
    Replies: 3
    Last Post: 11-11-2009, 02:51 PM
  5. JavaScript function help
    By suseman in forum Software Development
    Replies: 3
    Last Post: 26-05-2009, 05:11 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,881,734.34158 seconds with 16 queries