Async functions not friendly to promise extensions

medikoo medikoo+mozilla.org at medikoo.com
Fri Apr 14 11:06:31 UTC 2017


> var k = (async function() {await window.setTimeout(1000); return
randomPromiseSubtype})();

Assuming that setTmeout(1000) returns a promise, this code is equivalent to:

async function() {
    return setTimeout(1000).then(function () {
        return randomPromiseSubtype;
    });
};

I definitely would not expect that k in such case resolves with promise of
type of  randomPromiseSubtype, same as you never expect that
`setTimeout(1000).then()`may resolve with different promise types.

However if it's:

async function() {
    return randomPromiseSubtypeTimeout(1000).then(function () {
        return whateverPromise;
    });
};

It'll be great if k resolves with promise that shares the constructor with
promise returned by randomPromiseSubtypeTimeout(1000).then(...). That's my
point





--
View this message in context: http://mozilla.6506.n7.nabble.com/Async-functions-not-friendly-to-promise-extensions-tp364921p364926.html
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com.


More information about the es-discuss mailing list