Skip to content

Commit

Permalink
fix: wait for blocking resources before sending subsequent chunks (close
Browse files Browse the repository at this point in the history
  • Loading branch information
gbj committed Nov 23, 2024
1 parent 14eb707 commit c0df839
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions integrations/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,28 @@ pub trait ExtendResponse: Sized {
let (owner, stream) =
build_response(app_fn, additional_context, stream_builder);

let sc = owner.shared_context().unwrap();

let stream = stream.await.ready_chunks(32).map(|n| n.join(""));

let sc = owner.shared_context().unwrap();
while let Some(pending) = sc.await_deferred() {
pending.await;
}

let mut stream =
Box::pin(meta_context.inject_meta_context(stream).await);
let mut stream = Box::pin(
meta_context.inject_meta_context(stream).await.then({
let sc = Arc::clone(&sc);
move |chunk| {
let sc = Arc::clone(&sc);
async move {
while let Some(pending) = sc.await_deferred() {
pending.await;
}
chunk
}
}
}),
);

// wait for the first chunk of the stream, then set the status and headers
let first_chunk = stream.next().await.unwrap_or_default();
Expand Down

0 comments on commit c0df839

Please sign in to comment.