Skip to content

Commit

Permalink
TimeoutBody is now Unpin
Browse files Browse the repository at this point in the history
  • Loading branch information
hubert committed Mar 18, 2024
1 parent 15d32dc commit 7b69d2a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tower-http/src/timeout/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ pin_project! {
/// ```
pub struct TimeoutBody<B> {
timeout: Duration,
#[pin]
sleep: Option<Sleep>,
sleep: Option<Pin<Box<Sleep>>>,
#[pin]
body: B,
}
Expand Down Expand Up @@ -81,15 +80,14 @@ where
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<http_body::Frame<Self::Data>, Self::Error>>> {
let mut this = self.project();
let this = self.project();

// Start the `Sleep` if not active.
let sleep_pinned = if let Some(some) = this.sleep.as_mut().as_pin_mut() {
some
} else {
this.sleep.set(Some(sleep(*this.timeout)));
this.sleep.as_mut().as_pin_mut().unwrap()
};
if this.sleep.is_none() {
*this.sleep = Some(Box::pin(sleep(*this.timeout)));
}

let sleep_pinned = this.sleep.as_mut().map(|p| p.as_mut()).unwrap();

// Error if the timeout has expired.
if let Poll::Ready(()) = sleep_pinned.poll(cx) {
Expand All @@ -99,7 +97,7 @@ where
// Check for body data.
let frame = ready!(this.body.poll_frame(cx));
// A frame is ready. Reset the `Sleep`...
this.sleep.set(None);
*this.sleep = None;

Poll::Ready(frame.transpose().map_err(Into::into).transpose())
}
Expand Down

0 comments on commit 7b69d2a

Please sign in to comment.