Skip to content

Instantly share code, notes, and snippets.

@yangfch3
Last active September 13, 2018 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangfch3/038e0ca7f8e0f580207c55f1decd2998 to your computer and use it in GitHub Desktop.
Save yangfch3/038e0ca7f8e0f580207c55f1decd2998 to your computer and use it in GitHub Desktop.
[sleep 函数] #utils
/**
* @param {Number} sec Sleep second period.
*/
function sleep(sec) {
sec = +sec;
if (isNaN(sec)) {
throw new Error('sleep(): arg "sec" must be a number.');
}
const startTime = Date.now();
while(true) {
let now = Date.now();
if (now - startTime >= sec * 1000) {
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment