re: Why not to use setInterval VIEW POST

TOP OF THREAD FULL DISCUSSION
re: How about making an async version of setInterval? Something like... const setIntervalAsync = (fn, ms) => { fn().then(() => { setTimeo...
 
const delayReport = deplayMs => new Promise((resolve) => {
    setTimeout(resolve, deplayMs);
});

setIntervalAsync(async () => { console.log(new Date()); await delayReport(1000); }, 1000);

The print is

2018-08-26 09:13:43
2018-08-26 09:13:45
2018-08-26 09:13:47
2018-08-26 09:13:49
2018-08-26 09:13:51
2018-08-26 09:13:53

Cool man!

code of conduct - report abuse