Skip to content

Commit 709673d

Browse files
committed
Fix poll_close for Sink01As03 Compat
1 parent 6808a15 commit 709673d

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

futures-util/src/compat/compat01as03.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ where
214214
}
215215
Err(e) => Err(e),
216216
},
217-
None => Ok((Async01::NotReady, None)),
217+
None => f.poll_complete().map(|i| (i, None)),
218218
}) {
219219
Ok((Async01::Ready(_), _)) => task03::Poll::Ready(Ok(())),
220220
Ok((Async01::NotReady, item)) => {
@@ -226,10 +226,47 @@ where
226226
}
227227

228228
fn poll_close(
229-
self: Pin<&mut Self>,
229+
mut self: Pin<&mut Self>,
230230
lw: &LocalWaker,
231231
) -> task03::Poll<Result<(), Self::SinkError>> {
232-
self.poll_flush(lw)
232+
let item = self.buffer.take();
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)),
240+
Err(e) => Err(e)
241+
}
242+
},
243+
Ok(Async01::NotReady) => Ok((Async01::NotReady, None)),
244+
Err(e) => Err(e)
245+
}
246+
},
247+
Ok(AsyncSink01::NotReady(t)) => {
248+
Ok((Async01::NotReady, Some(t)))
249+
}
250+
Err(e) => Err(e),
251+
},
252+
None => match f.poll_complete() {
253+
Ok(Async01::Ready(_)) => {
254+
match <S as Sink01>::close(f) {
255+
Ok(i) => Ok((i, None)),
256+
Err(e) => Err(e)
257+
}
258+
},
259+
Ok(Async01::NotReady) => Ok((Async01::NotReady, None)),
260+
Err(e) => Err(e)
261+
},
262+
}) {
263+
Ok((Async01::Ready(_), _)) => task03::Poll::Ready(Ok(())),
264+
Ok((Async01::NotReady, item)) => {
265+
self.buffer = item;
266+
task03::Poll::Pending
267+
}
268+
Err(e) => task03::Poll::Ready(Err(e)),
269+
}
233270
}
234271
}
235272

0 commit comments

Comments
 (0)