const delay = ms => new Promise(res => setTimeout(res, ms));
async function notInstant() {
await delay(1);
return 1;
}
(async function() {
let a = notInstant();
console.log(a);
await delay(10000);
console.log("Still a promise after 10 seconds even though the function only waits for 1 millisecond =>", a);
a = await a;
console.log("Printing directly after but now is resolved with the correct value", a);
})();
I know that I shouldn't rely on setTimeout for these kinds of things, but I don't understand why printing the result after 10 seconds still gives an unresolved promise even though the function called only waits for 1 millisecond before returning a value. Then using await makes the result directly available for some reason.