Re: [whatwg/streams] [WritableStream] Shouldn't the state after writer.abort() be closed? (#464)

OK. So there are four possible things you might want to do as a producer to terminate your relationship with a writable stream:

- (A) queue up a close, so that after all pending writes finish, the stream goes to the closed state
- (B) queue up an error, so that after all pending writes finish, the stream goes to the errored state
- (C) immediately close. Throw away any queued writes, and then move the stream to the closed state
- (D) immediately error. Throw away any queued writes, and then move the stream to the errored state

Let's also write down what "closed" vs. "errored" means. The difference is kind of subtle.

- If a writable stream is closed:
  - `write()` will reject with a TypeError
  - `abort()` will be a no-op and return a promise fulfilled with undefined
  - `closed` will fulfill
  - `waitForDesiredSize()` will stay pending forever?
  - desiredSize will be 0?
  - `getWriter()` will return a writer with the above behaviors?
- If a writable stream is errored:
  - `write()` will reject with the stored error
  - `abort()` will reject wit the stored error
  - `closed` will reject with the stored error
  - `waitForDesiredSize()` will reject with the stored error
  - `desiredSize` will be null??
  - `getWriter()` will return a writer with the above behaviors?

The overall theme here is that any interactions with an errored writable stream will surface that error. So if you were expecting to do anything further with it, you will instead get an error, and hopefully surface it to your user/logs/etc. Whereas with a closed writable stream ... mostly nothing will happen? (`write()` is kind of an exception).

I am not sure the distinction here is a great distinction. I guess it is strongest for the `.closed` promise, which is useful, because of code like this:

```js
writer.write(a);
writer.write(b);
writer.write(c);
writer.close();

writer.closed.then(
  () => console.log("everything succeeded"),
  err => console.error("something went wrong in one of the writes or in closing", e)
);
```

---

Anyway, with this as background: My point of view is that (A) is very common, and that among the remaining possibilities, (D) is also common.

I think you are arguing that (C) is more common (or maybe just more consistent/preferred) than (D). Is that correct?

To me (D) seems more likely, because if you are throwing away queued data, something has likely gone wrong, and other parts of your program (mostly those that use `writer.closed`) should probably go down the error-handling path.

What do you think, given this framing of the problem?

---
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/streams/issues/464#issuecomment-224754621

Received on Wednesday, 8 June 2016 22:50:16 UTC