Sprawdzanie równości z obietnicą. Resolve vs.
/* Even though the return value of an async function behaves as if it's wrapped in a
Promise.resolve, they are not equivalent. */
//For example, the following:
async function foo() {
return 1
}
//...is similar to:
function foo() {
return Promise.resolve(1)
}
/*An async function will return a different reference, whereas Promise.resolve returns the
same reference if the given value is a promise.*/
const p = new Promise((res, rej) => {
res(1);
})
async function asyncReturn() {
return p;
}
function basicReturn() {
return Promise.resolve(p);
}
console.log(p === basicReturn()); // true
console.log(p === asyncReturn()); // false
Sven Snusberg