0

This is the code I'm wondering about.Why can I await all that function without return promise?

async function main() {
  await taskOne();
  await taskTwo();
  await taskThree();
  await taskFour();
}
main();


function taskOne() {
  setTimeout(function () {
    console.log("task 1");
  }, 500);
} 
function taskTwo() {
  console.log("task 2");
}
function taskThree() {
  setTimeout(function() {
    console.log("task 3");
  },  1000)
}
function taskFour() {
  console.log("task 4");
}

Can someone explain? Why isn't necessary to return promise?

  • [Because according to the spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await): when `await` encounters "Non-thenable value: An already-fulfilled Promise is constructed and used." – Terry Feb 26 '23 at 23:36

0 Answers0