Re: [whatwg/streams] When should closed promise be resolved? (Issue #1244)

So, the promise isn't resolved until the program has read the data. That is true. The issue is just that, once the data is read, `closed` is resolved... and the `read()` promise is resolved... but you added your handler to the `closed` promise before you added your handler to the `read()` promise, so the `closed` handler gets called first.

You can see this a bit more clearly with https://jsbin.com/quxonoxoye/1/edit?html,js,console . If you reorder the three `.then()` lines, you get the results printed in whatever order you added the handler. 

This is just how JS promises work. For any promises which are resolved in the same turn, it doesn't matter what order they are resolved in; it only matters what order they are subscribed to in. An even simpler example to show this is https://jsbin.com/jiviniveli/1/edit?html,js,console .

Thus, I'm pretty sure that even if we moved ReadableStreamClose after the chunk steps, then the code you give would still print "data not read yet", because you subscribed to the closed promise before you subscribed to the read() promise.

I don't think there's much for the spec to do here...

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

Message ID: <whatwg/streams/issues/1244/1279924400@github.com>

Received on Sunday, 16 October 2022 08:53:01 UTC