- From: Borewit <notifications@github.com>
- Date: Fri, 03 May 2019 10:18:04 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/issues/1000@github.com>
Or maybe I should say, I cannot find any way cancelling a ReadableStream without running into a synchronization issues. To cancel a _ReadableStream_ the reader has to release the lock on the stream. Releasing the [Reader](https://github.com/whatwg/streams/blob/6f94580f6731d1e017c516af097d47c45aad1f56/reference-implementation/lib/readable-stream.js#L811) requires to call [releaseLock()](https://github.com/whatwg/streams/blob/6f94580f6731d1e017c516af097d47c45aad1f56/reference-implementation/lib/readable-stream.js#L937). This call will throw an error of there is an outstanding [read](https://github.com/whatwg/streams/blob/6f94580f6731d1e017c516af097d47c45aad1f56/reference-implementation/lib/readable-stream.js#L913). ```JavaScript stream = response.body; // some ReadableStream; stream.getReader(); this.pendingRead = this.reader.read(); ``` Let's assume the read is still pending here.... At the same time, I would like to get rid of the stream. Aiming to call [releaseLock()](https://github.com/whatwg/streams/blob/6f94580f6731d1e017c516af097d47c45aad1f56/reference-implementation/lib/readable-stream.js#L937), when there is no ongoing read I try to used the promise returned by the [read](https://github.com/whatwg/streams/blob/6f94580f6731d1e017c516af097d47c45aad1f56/reference-implementation/lib/readable-stream.js#L913). ```JavaScript await this.pendingRead; // So let's wait for the read to complete, zzz.... // Should be fine now, right? this.reader.releaseLock(); // Kaboom: Tried to release a reader lock when that reader has pending read() calls un-settled ``` It looks like, the internal mechanism is resolved **after** the client side of the promise is resolved. The issue can be demonstrated on Google Chrome, I am not sure that reflects this reference implementation. I use a Readable stream return by [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). -- 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/1000
Received on Friday, 3 May 2019 17:18:26 UTC