Last active
September 14, 2024 00:54
-
-
Save imshvc/98511d798c001341716164419e7be7b8 to your computer and use it in GitHub Desktop.
JavaScript Sleep Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sleep for miliseconds | |
* @author Nurudin Imsirovic <[email protected]> | |
* @param {number} ms | |
* @returns {undefined} | |
*/ | |
function sleep(ms) { | |
if (0 >= ms) | |
return | |
let start = Date.now() | |
do {} while (ms > (Date.now() - start)) | |
} | |
// > console.log(Date.now()) | |
// > sleep(3000) | |
// > console.log(Date.now()) | |
// | |
// 1723950525789 | |
// 1723950528789 | |
// ^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment