Open this example in the interactive library
Source code
const source = () =>
new ReadableStream({
start(c) {
c.enqueue("a");
c.enqueue("b");
c.close();
},
});
console.log(
await (async () => {
let reason;
const s = new ReadableStream({
cancel(v) {
reason = v;
},
});
await s.cancel("finished");
return reason;
})(),
);
Sample output
finished
