Skip to content

Add poll_to_block to tokio_test::task::Spawn to advance futures as far as possible #8209

@wojciech-graj

Description

@wojciech-graj

Is your feature request related to a problem? Please describe.
My most common use-case for tokio-test's Spawn is to test futures in a synchronous context. In most cases, I don't care about the outcome to this specific call to poll, but about the outcome of polling the future once it has advanced as far as possible.

I believe that in most testing scenarios, you want something like the following:

let result = loop {
    let result = fut.poll();
    if result.is_ready() || !fut.is_woken() {
        break result;
    }
};

Describe the solution you'd like
I would like to add a function Spawn::poll_to_block(&mut self) that has the above logic.

Describe alternatives you've considered
N/A

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokio-testArea: The tokio-test crateC-feature-requestCategory: A feature request.M-taskModule: tokio/task

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions