From 425503d66d988d815ed6d23ea8a58ea250ef1438 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Sun, 23 Feb 2025 19:30:26 -0600 Subject: [PATCH] refactor --- src/client.rs | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/client.rs b/src/client.rs index b9ff7d3..d59f075 100644 --- a/src/client.rs +++ b/src/client.rs @@ -42,36 +42,32 @@ impl App { fn step(&mut self, cx: &mut Context<'_>) -> Result<()> { let mut stream = pin!(&mut self.stream); - match <_ as futures_sink::Sink>::poll_ready(stream.as_mut(), cx) { - Poll::Pending => {} - Poll::Ready(result) => { - result?; - if let Some(frame) = self.client.poll_send() { - stream - .as_mut() - .start_send(frame) - .context("stream.start_send")?; - tracing::debug!("Started send"); - } - match <_ as futures_sink::Sink>::poll_flush(stream.as_mut(), cx) { - Poll::Pending => {} - Poll::Ready(result) => { - result.context("poll_flush")?; - } + if let Poll::Ready(result) = + <_ as futures_sink::Sink>::poll_ready(stream.as_mut(), cx) + { + result?; + if let Some(frame) = self.client.poll_send() { + stream + .as_mut() + .start_send(frame) + .context("stream.start_send")?; + tracing::debug!("Started send"); + } + match <_ as futures_sink::Sink>::poll_flush(stream.as_mut(), cx) { + Poll::Pending => {} + Poll::Ready(result) => { + result.context("poll_flush")?; } } } - match stream.as_mut().poll_next(cx) { - Poll::Pending => {} - Poll::Ready(frame_opt) => { - let frame = frame_opt.context("Server closed cxn")?; - cx.waker().wake_by_ref(); - let frame = frame.context("network framing decode")?; - self.client - .handle_frame(frame.into()) - .context("client.handle_frame")?; - } + if let Poll::Ready(frame_opt) = stream.as_mut().poll_next(cx) { + let frame = frame_opt.context("Server closed cxn")?; + cx.waker().wake_by_ref(); + let frame = frame.context("network framing decode")?; + self.client + .handle_frame(frame.into()) + .context("client.handle_frame")?; } if self.timer.poll_tick(cx).is_ready() {