Skip to content

Commit

Permalink
reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow committed Oct 24, 2024
1 parent 2f479f0 commit 5074ab9
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions http/src/h1/dispatcher_uring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,23 @@ where
loop {
let buf = &mut *self.write_buf;

if buf.len() < W_LIMIT {
let res = poll_fn(|cx| match body.as_mut().poll_next(cx) {
Poll::Ready(res) => Poll::Ready(SelectOutput::A(res)),
Poll::Pending if buf.is_empty() => Poll::Pending,
Poll::Pending => Poll::Ready(SelectOutput::B(())),
})
.await;

match res {
SelectOutput::A(Some(Ok(bytes))) => {
encoder.encode(bytes, buf);
let res = poll_fn(|cx| match body.as_mut().poll_next(cx) {
Poll::Ready(res) => Poll::Ready(SelectOutput::A(res)),
Poll::Pending if buf.is_empty() => Poll::Pending,
Poll::Pending => Poll::Ready(SelectOutput::B(())),
})
.await;

match res {
SelectOutput::A(Some(Ok(bytes))) => {
encoder.encode(bytes, buf);
if buf.len() < W_LIMIT {
continue;
}
SelectOutput::A(Some(Err(e))) => return self.on_body_error(e).await,
SelectOutput::A(None) => break encoder.encode_eof(buf),
SelectOutput::B(_) => {}
}
SelectOutput::A(Some(Err(e))) => return self.on_body_error(e).await,
SelectOutput::A(None) => break encoder.encode_eof(buf),
SelectOutput::B(_) => {}
}

self.write_buf.write_io(&*self.io).await?;
Expand Down Expand Up @@ -444,19 +444,17 @@ impl<T> Notify<T> {
Notifier(self.0.clone())
}

async fn wait(&mut self) -> Option<T> {
fn wait(&mut self) -> impl Future<Output = Option<T>> + '_ {
poll_fn(|cx| {
let strong_count = Rc::strong_count(&self.0);
let mut inner = self.0.borrow_mut();
if let Some(val) = inner.val.take() {
return Poll::Ready(Some(val));
} else if strong_count == 1 {
} else if Rc::strong_count(&self.0) == 1 {
return Poll::Ready(None);
}
inner.waker = Some(cx.waker().clone());
Poll::Pending
})
.await
}
}

Expand Down

0 comments on commit 5074ab9

Please sign in to comment.