I have the following code:
function myPromiseFunc() {
return new Promise((resolve) => {
resolve(Promise.resolve(123));
});
}
As we know Promise.resolve method resolves Promise with a plain value immediately.
So Promise.resolve(123) -> Promise<fulfilled>
But:
console.log(myPromiseFunc());
will return Promise with status pending. Why? Is resolve function passed to executor async? Cause this:
setTimeout(console.log, 0, res);
will return Promise<fulfilled>.
I know Promises use microtasks but it's supposed to use only for handlers.
Promises/A+ says:
[[Resolve]](promise, x) -> If/when x is a promise and fulfilled, fulfill promise with the same value.
By the way. This snipped will return Promise<fulfilled>:
function myPromiseFunc() {
return new Promise((resolve) => {
resolve(123);
});
}
So it looks like resolve is async only when Promise passed as a value.
Please, help to understand. Thank you!