Javascript time_nanosleep : Miscellaneous Functions : PHP functions in JavaScript JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » PHP functions in JavaScript » Miscellaneous Functions »

 

Javascript time_nanosleep


Delay for a number of seconds and nano seconds
Example 1

Running
1.time_nanosleep(1, 2000000000); // delays for 3 seconds

Could return
1.true
function time_nanosleep(seconds, nanosecs) {
    // Delay for a number of seconds and nano seconds  
    // 
    // version: 902.122
    // discuss at: http://phpjs.org/functions/time_nanosleep
    // +   original by: Brett Zamir
    // %        note 1: For study purposes. Current implementation could lock up the user's browser.
    // %        note 1: Consider using setTimeout() instead.
    // %        note 2: Note that the following function's argument, contrary to the reference to
    // %        note 2: nanoseconds, does not start being significant until 1,000,000 nanoseconds (milliseconds),
    // %        note 2: since that is the smallest unit handled by JavaScript's Date function.
    // *     example 1: time_nanosleep(1, 2000000000); // delays for 3 seconds
    // *     returns 1: true
    var start = new Date().getTime();
    while (new Date() < (start + seconds*1000+nanosecs/1000000));
    return true;
}


HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo PHP functions in JavaScript
» Miscellaneous Functions