Skip to content

Capability to make an existing Stream participate in cooperative scheduling #7403

@pepijnve

Description

@pepijnve

Is your feature request related to a problem? Please describe.

I'm trying to make a Stream that represents some resource participate in cooperative scheduling. From reading the Tokio source code I think this would boil down to a decorator that looks something like this.

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
    let coop = ready!(tokio::task::coop::poll_proceed(cx));

    // do the actual Stream::poll_next
    let ret = self.poll_next_internal(cx);
    if ret.is_ready() {
        coop.made_progress();
    }
    ret
}

poll_proceed is not accessible so this is currently not possible. I don't think I can achieve the same result using consume_budget

Describe the solution you'd like

Some mechanism to make an existing pollable item participate in cooperative scheduling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-feature-requestCategory: A feature request.M-coopModule: tokio/coop

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions