Async functions not friendly to promise extensions

medikoo medikoo+mozilla.org at medikoo.com
Fri Apr 14 07:59:11 UTC 2017


While Promise methods and functions are friendly for it's extensions (or even
not direct extensions but just thenables), the async function will always
normalize it's result to instance of Promise, even it's ExtendedPromise,
e.g.:class ExtendedPromise extends Promise {};var extendedPromise = new
ExtendedPromise(function (resolve) { resolve();
});extendedPromise.then().constructor === ExtendedPromise // truevar asyncFn
= async function () { return extendedPromise; };asyncFn().constructor ===
ExtendedPromise // falseasyncFn().constructor === Promise // trueThat makes
it cumbersome if we work with promise extensions. What was the reasoning
behind such design?If not thenables in general, the promise extensions I
believe should be passed through (or copied via its constructor.resolve).



--
View this message in context: http://mozilla.6506.n7.nabble.com/Async-functions-not-friendly-to-promise-extensions-tp364921.html
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170414/8cdfca57/attachment.html>


More information about the es-discuss mailing list