Skip to content

futures_util: Add a poll_future function #2173

Closed
@fogti

Description

@fogti

original issue: smol-rs/smol#157

/// Pins a future and then polls it.
fn poll_future<T>(cx: &mut Context<'_>, fut: impl Future<Output = T>) -> Poll<T> {
    futures_util::pin_mut!(fut);
    fut.poll(cx)
}

This function is really useful in providing a bridge between simple async functions and poll_* methods; but appropriate documentation would need to be added, because it has the limitation that all state of the Future, which is only saved in the Future itself, and not via &mut bindings / etc., is lost after each yield, and the async fn should be designed to handle that case (e.g. be reentrant without strict dependency on local state; caching is ok, but external state shouldn't be corrupted if the Future yields and resets).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions