Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FuturesOrdered push_front does not work at the start #2663

Closed
conradludgate opened this issue Nov 12, 2022 · 0 comments · Fixed by #2664
Closed

FuturesOrdered push_front does not work at the start #2663

conradludgate opened this issue Nov 12, 2022 · 0 comments · Fixed by #2664
Labels
A-stream Area: futures::stream bug

Comments

@conradludgate
Copy link
Contributor

Running this code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=30c5f139539ccf5dd237299c88b56a2e

use std::future::ready;
use std::collections::VecDeque;
use futures::stream::{FuturesOrdered, StreamExt};

#[tokio::main]
async fn main() {
    let mut set = VecDeque::new();

    set.push_back(2);  // should be the last
    set.push_front(1); // should be the second
    set.push_front(0);  // should be the first
    
    let x: Vec<i32> = set.into_iter().collect();
    assert_eq!(x, [0, 1, 2]);

    let mut set = FuturesOrdered::new();
    
    set.push_back(ready(2));  // should be the last
    set.push_front(ready(1)); // should be the second
    set.push_front(ready(0));  // should be the first
    
    let x: Vec<i32> = set.collect().await;
    assert_eq!(x, [0, 1, 2]);
}

You see the assertion on the VecDeque passes, but the same assertion through FuturesOrdered fails.

I noticed this working on my own implementation in https://github.com/conradludgate/futures-buffered - I found that turning the usize counters into isize fixes it with no noticeable downsides.

@taiki-e taiki-e added bug A-stream Area: futures::stream labels Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stream Area: futures::stream bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants