Skip to content

Scoped tasks #3162

@jzrake

Description

@jzrake

I would love to be able to spawn non-'static tasks into the Tokio runtime, like so:

let local_data = LocalData::new();

let result = runtime.block_on_scoped(|scope| {

    let future_result = scope.spawn(async {
        local_data.result()
    });

    async {
        future_result.await.unwrap()
    }
});

This type of thing exists in Crossbeam: https://docs.rs/crossbeam/0.8.0/crossbeam/fn.scope.html
Someone wrote this for an older version of Tokio: https://docs.rs/tokio-scoped/0.1.0/tokio_scoped

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-feature-requestCategory: A feature request.M-taskModule: tokio/task

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions