-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define async algorithms (or "spec promises"???) #181
Comments
Summarising from IRC: In the "fetching scripts" case, I'd do something like:
…And rewrite "fetch a module script graph" to return synchronously. To allow "fetch a module script graph" to perform parallel fetches I'd do something like:
I guess that could be easier with spec promises:
|
@jakearchibald's way is better I think; we should try to move fetching-scripts toward that. The magic is in "wait", which ensures that the algorithm can be sync. I'll give it a try ... sometime ... and report back. At this point it seems more likely this will feed into HTML's event loop stuff than into Infra. |
Something that worries me is that to permit the natural expression of the streams API in JavaScript, "spec promises" need to use microtasks. To make matters worse, for efficiency purposes we need to be able to say something like
and have it work "in-place" without introducing an extra layer of microtask execution. |
These steps do a variety of things that only make sense back on the main thread. The intention here was that fetching not block the main thread. However, that is already the case even without going in parallel, given the "async algorithm" framework of the script-fetching algorithms. (That framework is admittedly a bit unclear; see whatwg/infra#181.)
These steps do a variety of things that only make sense back on the main thread. The intention here was that fetching not block the main thread. However, that is already the case even without going in parallel, given the "async algorithm" framework of the script-fetching algorithms. (That framework is admittedly a bit unclear; see whatwg/infra#181.)
These steps do a variety of things that only make sense back on the main thread. The intention here was that fetching not block the main thread. However, that is already the case even without going in parallel, given the "async algorithm" framework of the script-fetching algorithms. (That framework is admittedly a bit unclear; see whatwg/infra#181.)
These steps do a variety of things that only make sense back on the main thread. The intention here was that fetching not block the main thread. However, that is already the case even without going in parallel, given the "async algorithm" framework of the script-fetching algorithms. (That framework is admittedly a bit unclear; see whatwg/infra#181.)
These steps do a variety of things that only make sense back on the main thread. The intention here was that fetching not block the main thread. However, that is already the case even without going in parallel, given the "async algorithm" framework of the script-fetching algorithms. (That framework is admittedly a bit unclear; see whatwg/infra#181.)
https://html.spec.whatwg.org/#fetching-scripts makes use of these extensively, and seems like a reasonable model. However, there are several potential improvements we should discuss:
In a recent Chromium code review, I realized that using "asynchronously" is ambiguous. In particular, is it event-loop-async, or do I just mean "can also continue in a future event loop turn"? In general event loop integration is not spelled out. But in practice this leads to an observable difference. I think in most cases I want to allow sync execution of the algorithm, e.g. early-error cases shouldn't need to yield to the event loop before continuing. This should be clarified, probably by defining "asynchronous algorithm" or similar in Infra and then linking to it.
Should we have separate error and success channels? #fetching-scripts uses "null"; maybe it should use "failure" instead. I guess that makes more sense than separate channels, since it matches how we do most sync algorithms? Or should there be something more analogous to thrown exceptions?
This model is very "callback-ish". Should we try to do something more promise-ish or await-ish? I'm not sure what that would mean; #fetching-scripts already feels fairly await-ish, e.g. we don't indent the steps after getting the result. But it's worth thinking about.
For those last two points, it basically boils down to looking at #fetching-scripts with fresh eyes and letting me know how you would do them differently.
The text was updated successfully, but these errors were encountered: