mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-11-08 18:02:23 +05:30
JavaScript: add busy-loop-delay.js
This commit is contained in:
parent
510bf7a595
commit
7a3d73a6bf
14
js-programming/busy-loop-delay.js
Normal file
14
js-programming/busy-loop-delay.js
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* busy-loop-delay.js
|
||||
*
|
||||
* Author: Intel A80486DX2-66
|
||||
* License: Creative Commons Zero 1.0 Universal
|
||||
*/
|
||||
|
||||
let measureEpoch = () => Number(new Date())
|
||||
|
||||
function busyLoopDelay(ms) {
|
||||
let currentTime = measureEpoch(), nextTime = currentTime + ms
|
||||
if (nextTime > currentTime)
|
||||
while (measureEpoch() < nextTime);
|
||||
}
|
Loading…
Reference in New Issue
Block a user