- From: Luca Casonato <notifications@github.com>
- Date: Mon, 12 Jun 2023 08:37:20 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/pull/1283/c1587585213@github.com>
> I think calling it before is better.
Ok, I'll change that. This opens up a question on promise handling:
```js
const ts = new TransformStream({
async cancel(reason) {
console.log("t.cancel start with", reason);
await delay(100);
console.log("t.cancel end");
throw "t.cancel error";
},
});
console.log("ts constructed");
ts.readable.cancel("rs.cancel error")
.then(() => console.log("rs.cancel fulfilled"))
.catch((err) => console.log("rs.cancel rejected with", err));
ts.writable.abort("ws.abort error")
.then(() => console.log("ws.abort fulfilled"))
.catch((err) => console.log("ws.abort rejected with", err));
console.log("started rs.cancel and ws.abort");
```
I think the logical ordering of logs is:
```
# a-1
ts constructed
t.cancel start with rs.cancel error
started rs.cancel and ws.abort
t.cancel end
rs.cancel rejected with t.cancel error
ws.abort rejected with t.cancel error
```
But the following are also possible:
```
# a-2
ts constructed
t.cancel start with rs.cancel error
started rs.cancel and ws.abort
ws.abort fulfilled
t.cancel end
rs.cancel rejected with t.cancel error
```
```
# a-3
ts constructed
t.cancel start with rs.cancel error
started rs.cancel and ws.abort
t.cancel end
rs.cancel fulfilled
ws.abort fulfilled
```
Also consider:
```js
const ts = new TransformStream({
flush() { console.log("t.flush") },
async cancel(reason) {
console.log("t.cancel start with", reason);
await delay(100);
console.log("t.cancel end");
throw "t.cancel error";
},
});
console.log("ts constructed");
ts.readable.cancel("rs.cancel error")
.then(() => console.log("rs.cancel fulfilled"))
.catch((err) => console.log("rs.cancel rejected with", err));
ts.writable.close()
.then(() => console.log("ws.close fulfilled"))
.catch((err) => console.log("ws.close rejected with", err));
console.log("started rs.cancel and ws.close");
```
Here similar options are possible:
```
# b-1
ts constructed
t.cancel start with rs.cancel error
started rs.cancel and ws.close
t.cancel end
rs.cancel rejected with t.cancel error
ws.close rejected with t.cancel error
```
```
# b-2
ts constructed
t.cancel start with rs.cancel error
started rs.cancel and ws.close
ws.close fulfilled
t.cancel end
rs.cancel rejected with t.cancel error
```
```
# b-3
ts constructed
t.cancel start with rs.cancel error
started rs.cancel and ws.close
t.cancel end
rs.cancel fulfilled
ws.close fulfilled
```
These each also have effect on whether the error is visible in `writer.closed` or not. In a-1 and b-1 examples `writer.closed` would reject, in a-2, a-3, b-2, and b-3 the it resolves to `undefined`.
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1283#issuecomment-1587585213
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/streams/pull/1283/c1587585213@github.com>
Received on Monday, 12 June 2023 15:37:26 UTC