Hacker News new | ask | show | jobs
by explodingwaffle 954 days ago
Tangential to some comments here: Why does the standard library not have block_on?
2 comments

As far as I know, the proposal to add one was determined to need an RFC: https://github.com/rust-lang/rust/pull/65875
Another instance of a trivial and obvious feature that can only really be designed one way that is not implemented 4 years after initial proposal.
I am not fully sure I agree with the first part of your assessment, but I share the frustration that a feature like this, which would be useful and is not particularly large, is basically ignored by the working group, while larger, more controversial, and less useful features, like keyword generics, are pursued while the more useful things languish.
As the person who proposed this feature - among lots of other ones for async Rust, like run-to-completion async functions (https://github.com/Matthias247/rfcs/blob/e7fd7042f8069e9126e...), structured concurrency, cancellation tokens, etc) - I can unfortunately share this sentiment. It seemed really hard to land anything in async Rust since the priorities don't seem overly clear. Therefore I put a pause on all contribution attempts and went back to just using Rust as a user.
block_on is a executor that polls a future until it returns ready. If the future is not ready then the executor wait until it is woken up. If you poll a future that relies on a specific runtime (I.g. A async library that uses Tokio) to wake up the executor, with a simple block_on you will get stuck.

A generic block_on in std would be a footgun for new programmers I believe.

The proposals to add block_on generally include an executor like pollster.