From 7a3d73a6bfc5b2830445668f2d8b9801d9c400cd Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Wed, 31 Jan 2024 23:46:48 +0300 Subject: [PATCH] JavaScript: add busy-loop-delay.js --- js-programming/busy-loop-delay.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 js-programming/busy-loop-delay.js diff --git a/js-programming/busy-loop-delay.js b/js-programming/busy-loop-delay.js new file mode 100644 index 0000000..df199b5 --- /dev/null +++ b/js-programming/busy-loop-delay.js @@ -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); +}