[tracking] spawning non-Send tasks
- Dominant language
- Rust
- Stars
- 4.1k
- Forks
- 339
- PR merge metrics
- No merged PRs in 30d
Description
In https://github.com/async-rs/async-std/pull/251 we discussed the option of adding a `task::spawn_local` method, similar to @alexcrichton's design of [`spawn_local` in wasm-bindgen-futures](https://docs.rs/wasm-bindgen-futures/0.4.3/wasm_bindgen_futures/fn.spawn_local.html). 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`](https://docs.rs/async-std/0.99.11/async_std/task/fn.yield_now.html) out of the box.
## Example
```rust
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._
Contributor guide
Assessment
This issue has not been assessed yet.