rust-lang / futures-rs

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

`now_or_never` name and documentation is misleading and ambiguous respectively #2871

Open dspyz-matician opened 1 month ago

dspyz-matician commented 1 month ago

IIUC, when used with a mutable reference to a future (&mut Fut), now_or_never effectively polls Fut (similar to the poll! macro but without needing an async context). In the event of a None, the future is still guaranteed to eventually complete if awaited on or if it's a tokio join handle or something (assuming it's not otherwise aborted and doesn't run forever), so there's no sense in which not completing now means it will "never" complete.

This is sometimes extremely useful (arguably moreso than calling it on a future by value) and there doesn't seem to be any other safe method which provides the same functionality, but the naming is pretty misleading and the docs don't clarify this behavior at all.