Reputation: 842
How can I run an async func in a setInterval
like in the example below?
setInterval(async () => {
}, millisPerHour);
Upvotes: 0
Views: 305
Reputation: 125
try with this code
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
const result = await resolveAfter2Seconds();
console.log(result);
// expected output: "resolved"
}
asyncCall();`
Upvotes: 2