Implement promiseResolve(value), which behaves like Promise.resolve.
await promiseResolve(42); // 42
const p = Promise.resolve('x');
promiseResolve(p) === p; // true (native promises are returned as-is)
const thenable = {
then(onFulfilled) {
onFulfilled('adopted');
},
};
await promiseResolve(thenable); // 'adopted'
Promise.resolve. You may use new Promise.value is a native promise whose constructor is exactly Promise, return the same object.Promise subclass, is wrapped in a new native promise that follows it.then property) are adopted. The returned promise follows whatever the thenable does:
then throws before either callback was called, the promise rejects with that error.then property throws (a throwing getter), the promise rejects with that error.then is called asynchronously, in a later microtask, not during promiseResolve.Promise.resolve adopt thenables at all, instead of only real promises?await-ing a plain value?Spotted a mistake or a rights concern? Report an issue