Skip to content

[tracking] spawning non-Send tasks #457

Open
@yoshuawuyts

Description

@yoshuawuyts

In #251 we discussed the option of adding a task::spawn_local method, similar to @alexcrichton's design of spawn_local in wasm-bindgen-futures. This is a tracking issue for that design to get feedback on whether people would want this, and how we would go about implementing this.

I'd imagine we would introduce a new API; task::spawn_local which takes a non-Send Future, and ensures it's polled to completion on the current thread. This would interact seamlessly with task::yield_now out of the box.

Example

use async_std::task;

task::spawn(async move {
    task::sleep(Duration::from_secs(1)).await;

    // The async code in this block will never be moved between threads.
    task::spawn_local(async {
        task::sleep(Duration::from_secs(1)).await;
    }).await;
}).await;

Note: task::sleep does implement Send, but it was an easy example to use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api designOpen design questions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions