Skip to content
This repository has been archived by the owner on Aug 29, 2021. It is now read-only.

Normative: Flush Job Queue between module imports #51

Merged
merged 1 commit into from
Feb 28, 2019

Conversation

littledan
Copy link
Member

Closes #47, #43, #48, #50

@littledan
Copy link
Member Author

Thinking about this a bit more, I prefer this option to #49, since it's more consistent with https://www.w3.org/2001/tag/doc/promises-guide and achieves the ordering invariants that we need.

@guybedford
Copy link
Collaborator

Does this approach mean that in the following case:

a.js

import './b.js';

b.js

await 0;

execution will run completely synchronously?

@littledan
Copy link
Member Author

littledan commented Feb 25, 2019

@guybedford

execution will run completely synchronously?

Well, depends what you mean by "synchronously", but basically yes. Here's another example of an observable semantic difference between this PR and #49 (I imagine this kind of thing might be what you're getting at):

a.mjs

import "./b.mjs";
import "./c.mjs";
console.log("a");

b.mjs

console.log("b1");
await 0;
console.log("b2");

c.mjs

console.log("c");

file.html

<script type=module src="a.mjs"></script>

In this PR, the order would be b1, b2, c, a, whereas in #49, the order would be b1, c, b2, a.

I'm wondering if it might not be possible to:

I don't understand how this would work. Ultimately, there are two different Promises and capabilities: the one that's used within the cycle, and the one that's exposed at the end. If overwriting the same slot is seen as messy, we could use two different ones. (I like how the spec is based on Promises, not capabilities, where possible since it feels like giving "least authority", but I don't think that's an extremely important concern here.)

@littledan
Copy link
Member Author

To clarify, async 0 will still involve a microtask queue operation, and still happen asynchronously. The semantics of the top level of a module are, in the end, just the same as an async function. It's just that we flush the microtask queue between executing modules.

@guybedford
Copy link
Collaborator

I'm still against this approach, and have deep concerns about its implications for JS optimizations in future. This introduces a whole new class of bugs when using tools like Rollup, and I think #47 would be a far more sensible and intuitive approach.

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

Successfully merging this pull request may close these issues.

2 participants