rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.38k stars 622 forks source link

Fix missing wake() in PendingOnce #2799

Closed nickd-airo closed 10 months ago

nickd-airo commented 10 months ago

PendingOnce should wake() before returning Pending, otherwise executors may not poll() again.

Without this change, the following code blocks forever:

#[test]
fn test_block_on() {
    async fn test_fut() {
        futures::pending!();
    }
    futures::executor::block_on(test_fut())
}
taiki-e commented 10 months ago

The current one is the correct behavior. Your change makes the executor immediately re-poll the future, which is not the intended behavior of this macro. See also docs.

Similarly, when using this macro, it must be ensured that wake is called somewhere when further progress can be made.

So I'm going to close this, but thanks anyway for the PR.

nickd-airo commented 10 months ago

Sorry about that, I didn't read the documentation properly. Thanks for clarifying!