Skip to content

Commit

Permalink
Merge pull request rust-lang#45 from Stebalien/fix-stream-poll
Browse files Browse the repository at this point in the history
Make stream::Fuse return None after finishing, not NotReady
  • Loading branch information
alexcrichton authored Aug 12, 2016
2 parents 8ab5c59 + 82c09e3 commit c4af380
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/stream/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ impl<S: Stream> Stream for Fuse<S> {

fn poll(&mut self, task: &mut Task) -> Poll<Option<S::Item>, S::Error> {
let ret = self.stream.as_mut().map(|s| s.poll(task));
match ret {
Some(Poll::Ok(None)) => self.stream = None,
_ => {}
if let Some(Poll::Ok(None)) = ret {
self.stream = None;
}
ret.unwrap_or(Poll::NotReady)
ret.unwrap_or(Poll::Ok(None))
}

fn schedule(&mut self, task: &mut Task) {
Expand Down
14 changes: 13 additions & 1 deletion tests/stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate futures;

use futures::{failed, finished, Future, promise};
use futures::{failed, finished, Future, promise, Poll, Task};
use futures::stream::*;

mod support;
Expand Down Expand Up @@ -77,6 +77,18 @@ fn adapters() {
assert_done(|| list().skip(2).collect(), Ok(vec![3]));
}

#[test]
fn fuse() {
let mut stream = list().fuse();
let mut task = Task::new();
assert_eq!(stream.poll(&mut task), Poll::Ok(Some(1)));
assert_eq!(stream.poll(&mut task), Poll::Ok(Some(2)));
assert_eq!(stream.poll(&mut task), Poll::Ok(Some(3)));
assert_eq!(stream.poll(&mut task), Poll::Ok(None));
assert_eq!(stream.poll(&mut task), Poll::Ok(None));
assert_eq!(stream.poll(&mut task), Poll::Ok(None));
}

// #[test]
// fn adapters_poll() {
// assert_eq!(collect_poll(list().map(|a| a + 1)), Ok(vec![2, 3, 4]));
Expand Down

0 comments on commit c4af380

Please sign in to comment.