Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

A question about async await with native promise.(try to implement zone.js for async/await) #12

Open
JiaLiPassion opened this issue Oct 21, 2018 · 1 comment

Comments

@JiaLiPassion
Copy link

The following code

async function detect() { }
const r = detect();
const nativeThen = r.proto.then;
r.proto.then = function () {
console.log('promise.then');
return nativeThen.apply(this, arguments);
}

async function test1() {
console.log('before await');
const r = await test();
console.log('after await');
}

test1();
console.log('end');

// the output will be
// before await
// end
// promise.then, question is why promise.then is after end?
// after await
The nativePromise.then will be executed after end, I don't understand why, any help will be appreciated.

And What is the current status of zone proposal? Thanks!

@danielgindi
Copy link

This is because the Promise callbacks are always scheduled on the microtask queue. Which happens after the current execution context finishes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants