setInterval(() => {
// do some stuff
}, 1000)
const foo = async () => {
const res = await api_call();
const do_stuff();
}
await foo();
Will the foo
function block the setInterval
when its callback is due to be executed?
setInterval(() => {
// do some stuff
}, 1000)
const foo = async () => {
const res = await api_call();
const do_stuff();
}
await foo();
Will the foo
function block the setInterval
when its callback is due to be executed?
2
Answers
I think your question can be down to the prioritization between the callback of
setInterval
and foo() function under single threadIf
api_call
returns a promise, theawait
function effectively ‘pauses’ thefoo
function until something causes the promise to resolve.If 1000ms pass before that happens, the timeout code executes first.