1 hour ago · 8 min read1664 words · Tech · hide · 0 comments

IntroductionIn async Rust the Future::poll method is called to progress the state of the future, which reports its progress via the Poll enum. This enum contains two variants: Poll::Pending: means that the future is not yet ready to produce a value, and poll will need to be invoked again later. Poll::Ready(T): means the future is ready to yield some value T. Futures are called that because they will eventually resolve to a value, in the future. But that’s value singular, not values plural. The stdlib documentation does not clearly make this guarantee (though it should), and the ecosystem doesn’t always implement this correctly (though it also should). But the intent is clear: one future should only ever yield one value. Now what should happen when you try and call Future::poll again after it has already yielded a value? The Future trait docs have the following to say: Once a future has completed (returned Ready from poll), calling its poll method again may panic, block forever, or…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.