Future streams in Localpool starving

Hi
In an example code with a LocalPool executor running two async functions.
Each async function looks something like

async fn xyz() {
    let stream = ....
    loop {
        stream.next().await;
        ....
    }
}

If one stream always return Poll:Ready, the other will starve, even if ready. I would expect them to round robin. Is this by design or a flaw?
Cheers!

If one stream is always ready, then the future just keeps running. The choice of executor doesn't have anything to do with it. You could write a little future that "yields" back to the executor by returning Pending once and then Ready to cooperatively allow other futures to run and call that periodically. Tokio has one, but it's not runtime specific so that could easily move to the futures crate: yield_now.rs.html -- source

Thanks for the quick reply! That looks like a neat solution, I'll give it a try :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.