Say I replace the global Promise
object with Bluebird promises (such as to support cancellation). If I then write a function using async
/await
:
async function foo() {
const response = await fetch(...);
const result = doSomethingWith(response);
return result;
}
What kind of Promise is returned here?
IIRC when the code is compiled down to ES5, it will indeed return a cancellable Bluebird promise, since async/await is translated to use the global Promise object internally. But in ES7, where async/await is a native construct, will it use the Promise constructor in the global object, or is it hard-coded to use the native one?
Native syntax will always create native promise objects from the current realm, no matter what value the global Promise
variable in the realm has.
A transpiler should strive to recreate that experience, however when it also includes a promise shim (which might be configured to be a custom library) that needs to live somewhere and for simplicity will probably depend on the global Promise
value.