Re: [whatwg/fetch] Odd format for fetch callbacks (#536)

Everything in https://github.com/whatwg/fetch/issues/536#issuecomment-775170346 makes general sense to me. In particular, I'd love to be able to write spec text that's like the following:

> 1. Fetch _request_, using the following steps to [process the response] _response_:
>    1. ... stuff with _response_ ...

I think it'd be somewhat tempting to be able to write text like the following too:

> 1. Fetch _request_. When the fetch completes with _response_, continue onto the following steps:
> 1. ... stuff with _response_, but not indented ...

but on balance I think this is inadvisable, as then you can easily get into trouble if you accidentally use "return" or "throw" from those non-idented steps.

I'm thinking how this (indented) pattern would look if we carried it over to https://html.spec.whatwg.org/#fetching-scripts, and I think it would be reasonable. We'd define an explicit callback parameter (e.g. "process the module script") for those, and thread everything through with some extra indenting, instead of using the current "Asynchronously complete this algorithm with X". The most complex it would get would be in https://html.spec.whatwg.org/#fetch-the-descendants-of-a-module-script step 8, which could be formalized nicely with infrastructure like this, at the cost of some complexity. (It could also allow us to explicitly terminate ongoing fetches if one of the fetches fail.)

On an editorial side, for some reason callbacks namedLikeThis seem ickier, so if we made them real optional paramters I'm not sure I'd want to update their names, but that doesn't matter much.

> We need to have an easy way to get at the bytes of a response body. (We could just expose a specification-only byte sequence on responses. We could allow specifications to treat ReadableStream of responses for which end-of-file has run as equivalent to a byte sequence (perhaps with some magic conversion algorithm that does the relevant asserts). Thoughts appreciated.)

Exposing a byte sequence seems critical. I think getting the byte sequence should consume the body though, so this would be a byte sequence variant of the spec's current "consume body" algorithm. It could still operate on streams, with relevant asserts. I guess it would need to be called from the main thread, so it'd be called from "process response" hooks?

> We might also want a return value for main thread callers that is equivalent to the above except that it would be filled in from tasks.

What would this do besides expose terminate? How would one use it?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/536#issuecomment-775355188

Received on Monday, 8 February 2021 18:36:50 UTC