Skip to content

Commit 3c83730

Browse files
committed
Clean up poll_close for SinkCompat layer
1 parent 58f99d9 commit 3c83730

File tree

1 file changed

+15
-35
lines changed

1 file changed

+15
-35
lines changed

futures-util/src/compat/compat01as03.rs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<St: Stream01> Stream03 for Compat01As03<St> {
122122

123123
/// Converts a futures 0.1 Sink object to a futures 0.3-compatible version
124124
#[derive(Debug)]
125-
#[must_use = "futures do nothing unless polled"]
125+
#[must_use = "sinks do nothing unless polled"]
126126
pub struct Compat01As03Sink<S, SinkItem> {
127127
pub(crate) inner: Spawn01<S>,
128128
pub(crate) buffer: Option<SinkItem>,
@@ -234,43 +234,23 @@ where
234234
let item = self.buffer.take();
235235
let close_started = self.close_started;
236236

237-
match self.in_notify(lw, |f| match item {
238-
Some(i) => match f.start_send(i) {
239-
Ok(AsyncSink01::Ready) => {
240-
match f.poll_complete() {
241-
Ok(Async01::Ready(_)) => {
242-
match <S as Sink01>::close(f) {
243-
Ok(i) => Ok((i, None, true)),
244-
Err(e) => Err(e)
245-
}
246-
},
247-
Ok(Async01::NotReady) => Ok((Async01::NotReady, None, false)),
248-
Err(e) => Err(e)
237+
let result = self.in_notify(lw, |f| {
238+
if !close_started {
239+
if let Some(item) = item {
240+
if let AsyncSink01::NotReady(item) = f.start_send(item)? {
241+
return Ok((Async01::NotReady, Some(item), false));
249242
}
250-
},
251-
Ok(AsyncSink01::NotReady(t)) => {
252-
Ok((Async01::NotReady, Some(t), close_started))
253-
}
254-
Err(e) => Err(e),
255-
},
256-
None => if close_started {
257-
match <S as Sink01>::close(f) {
258-
Ok(i) => Ok((i, None, true)),
259-
Err(e) => Err(e)
260243
}
261-
} else {
262-
match f.poll_complete() {
263-
Ok(Async01::Ready(_)) => {
264-
match <S as Sink01>::close(f) {
265-
Ok(i) => Ok((i, None, true)),
266-
Err(e) => Err(e)
267-
}
268-
},
269-
Ok(Async01::NotReady) => Ok((Async01::NotReady, None, close_started)),
270-
Err(e) => Err(e)
244+
245+
if let Async01::NotReady = f.poll_complete()? {
246+
return Ok((Async01::NotReady, None, false));
271247
}
272-
},
273-
}) {
248+
}
249+
250+
Ok((<S as Sink01>::close(f)?, None, true))
251+
});
252+
253+
match result {
274254
Ok((Async01::Ready(_), _, _)) => task03::Poll::Ready(Ok(())),
275255
Ok((Async01::NotReady, item, close_started)) => {
276256
self.buffer = item;

0 commit comments

Comments
 (0)