SetTimeout in promise how it works?

Viewed 27

I was wondering how this code will work I didn't understand if the blockMyCodeFor10Min function did work on the main thread of js and if the main thread is used why do people use setTimeout(func,0) inside a promise?

function blockMyCodeFor10Min(res) {
  let oldTime = Date.now();
  while (Date.now() - oldTime < 600000);
  res();
}

const x = async () => {
  return new Promise((res) => {
    setTimeout(() => {
      blockMyCodeFor10Min(res);
    }, 0);
  });
};
x();
0 Answers
Related