Skip to content

Commit

Permalink
wasm: fix premature abort for streaming bodies (#1782)
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Mar 17, 2023
1 parent 4db868b commit df2b3ba
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/wasm/response.rs
Expand Up @@ -136,11 +136,14 @@ impl Response {
#[cfg(feature = "stream")]
pub fn bytes_stream(self) -> impl futures_core::Stream<Item = crate::Result<Bytes>> {
let web_response = self.http.into_body();
let abort = self._abort;
let body = web_response
.body()
.expect("could not create wasm byte stream");
let body = wasm_streams::ReadableStream::from_raw(body.unchecked_into());
Box::pin(body.into_stream().map(|buf_js| {
Box::pin(body.into_stream().map(move |buf_js| {
// Keep the abort guard alive as long as this stream is.
let _abort = &abort;
let buffer = Uint8Array::new(
&buf_js
.map_err(crate::error::wasm)
Expand Down

0 comments on commit df2b3ba

Please sign in to comment.