Skip to content

Commit 47797e8

Browse files
LucioFrancoNemo157
authored andcommitted
Clean up poll_close for SinkCompat layer
1 parent 121afa8 commit 47797e8

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
@@ -118,7 +118,7 @@ impl<St: Stream01> Stream03 for Compat01As03<St> {
118118

119119
/// Converts a futures 0.1 Sink object to a futures 0.3-compatible version
120120
#[derive(Debug)]
121-
#[must_use = "futures do nothing unless polled"]
121+
#[must_use = "sinks do nothing unless polled"]
122122
pub struct Compat01As03Sink<S, SinkItem> {
123123
pub(crate) inner: Spawn01<S>,
124124
pub(crate) buffer: Option<SinkItem>,
@@ -230,43 +230,23 @@ where
230230
let item = self.buffer.take();
231231
let close_started = self.close_started;
232232

233-
match self.in_notify(lw, |f| match item {
234-
Some(i) => match f.start_send(i) {
235-
Ok(AsyncSink01::Ready) => {
236-
match f.poll_complete() {
237-
Ok(Async01::Ready(_)) => {
238-
match <S as Sink01>::close(f) {
239-
Ok(i) => Ok((i, None, true)),
240-
Err(e) => Err(e)
241-
}
242-
},
243-
Ok(Async01::NotReady) => Ok((Async01::NotReady, None, false)),
244-
Err(e) => Err(e)
233+
let result = self.in_notify(lw, |f| {
234+
if !close_started {
235+
if let Some(item) = item {
236+
if let AsyncSink01::NotReady(item) = f.start_send(item)? {
237+
return Ok((Async01::NotReady, Some(item), false));
245238
}
246-
},
247-
Ok(AsyncSink01::NotReady(t)) => {
248-
Ok((Async01::NotReady, Some(t), close_started))
249-
}
250-
Err(e) => Err(e),
251-
},
252-
None => if close_started {
253-
match <S as Sink01>::close(f) {
254-
Ok(i) => Ok((i, None, true)),
255-
Err(e) => Err(e)
256239
}
257-
} else {
258-
match f.poll_complete() {
259-
Ok(Async01::Ready(_)) => {
260-
match <S as Sink01>::close(f) {
261-
Ok(i) => Ok((i, None, true)),
262-
Err(e) => Err(e)
263-
}
264-
},
265-
Ok(Async01::NotReady) => Ok((Async01::NotReady, None, close_started)),
266-
Err(e) => Err(e)
240+
241+
if let Async01::NotReady = f.poll_complete()? {
242+
return Ok((Async01::NotReady, None, false));
267243
}
268-
},
269-
}) {
244+
}
245+
246+
Ok((<S as Sink01>::close(f)?, None, true))
247+
});
248+
249+
match result {
270250
Ok((Async01::Ready(_), _, _)) => task03::Poll::Ready(Ok(())),
271251
Ok((Async01::NotReady, item, close_started)) => {
272252
self.buffer = item;

0 commit comments

Comments
 (0)