function first(){
console.log(\'first\')
}
function second(){
console.log(\'second\')
}
let interval = async ()=>{
await setInterval(first,2000)
await set
setInterval
doesn't play well with promises because it triggers a callback multiple times, while promise resolves once.
It seems that it's setTimeout
that fits the case. It should be promisified in order to be used with async..await
:
async () => {
await new Promise(resolve => setTimeout(() => resolve(first()), 2000));
await new Promise(resolve => setTimeout(() => resolve(second()), 2000));
}