Since setTimeout doesn't guarantee the delay of specified ms, the implementation of delay function in index.js can be improved with the help of while loop.
function delay(ms) {
return new Promise((resolve) => {
const now = new Date().getTime();
while (new Date().getTime() < now + ms) {
/* Do nothing */
}
resolve(null);
});
}
Since setTimeout doesn't guarantee the delay of specified ms, the implementation of delay function in index.js can be improved with the help of while loop.
Reference Reading: https://www.gimtec.io/articles/settimeout-does-not-guarantee-time-to-execution/