1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-08 08:54:34 +05:30

JavaScript: add busy-loop-delay.js

This commit is contained in:
Intel A80486DX2-66 2024-01-31 23:46:48 +03:00
parent 510bf7a595
commit 7a3d73a6bf
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

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