Hey! I'm YCMJason, a Software Engineer in London 👨💻. Love diving into tech puzzles and sharing them! 🧩
All views expressed here are my own opinions, so please take them with a pinch of salt! 🧂
constdelayReport=deplayMs=>newPromise((resolve)=>{setTimeout(resolve,deplayMs);});setIntervalAsync(async()=>{try{constseed=Math.floor((Math.random()*100)+1);if(seed%2===0){console.log(newDate());awaitdelayReport(500);}else{thrownewError('get a random error');}}catch(e){console.error(e);}},1000);
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How about making an async version of setInterval? Something like...
So we can just do
Which would call fetch every 3000ms properly.
P.S. Haven't really tested it, just an idea...
Will test it and let you know. :)
Hello, I am curious If you tested it :)
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!
And handle errors: