diff options
Diffstat (limited to 'ext/web/stream_resource.rs')
-rw-r--r-- | ext/web/stream_resource.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/ext/web/stream_resource.rs b/ext/web/stream_resource.rs index e19954fdc..b35d4c302 100644 --- a/ext/web/stream_resource.rs +++ b/ext/web/stream_resource.rs @@ -364,6 +364,15 @@ impl ReadableStreamResource { .read(limit) .map(|buf| buf.unwrap_or_else(BufView::empty)) } + + fn close_channel(&self) { + // Trigger the promise in JS to cancel the stream if necessarily + self.data.completion.complete(true); + // Cancel any outstanding read requests + self.cancel_handle.cancel(); + // Close the channel to wake up anyone waiting + self.channel.close(); + } } impl Resource for ReadableStreamResource { @@ -376,8 +385,13 @@ impl Resource for ReadableStreamResource { } fn close(self: Rc<Self>) { - self.cancel_handle.cancel(); - self.channel.close(); + self.close_channel(); + } +} + +impl Drop for ReadableStreamResource { + fn drop(&mut self) { + self.close_channel(); } } |