-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tracking] spawning non-Send tasks #457
Comments
tokio 0.2.2 added Example: use std::rc::Rc;
use tokio::task;
let unsend_data = Rc::new("my unsend data...");
let mut rt = Runtime::new().unwrap();
// Construct a local task set that can run `!Send` futures.
let local = task::LocalSet::new();
// Run the local task group.
local.block_on(&mut rt, async move {
let unsend_data = unsend_data.clone();
// `spawn_local` ensures that the future is spawned on the local
// task group.
task::spawn_local(async move {
println!("{}", unsend_data);
// ...
}).await.unwrap();
}); |
I'm not sure if I like that API. That seems to push the task group into a global? What happens when two local groups nest? |
I didn't experiment a lot with it, but as I understood you can not have nested groups, because a group is scheduled by |
I'd like to put in a vote for this. As I said on Discord:
|
There is now unstable function It is unfortunately not marked as #[cfg(feature = "default")]
pub use spawn_local::spawn_local; needs to be changed to: #[cfg(feature = "default")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
pub use spawn_local::spawn_local; |
Right - I'm saying, I would be delighted if this were stabilized. :) |
In #251 we discussed the option of adding a
task::spawn_local
method, similar to @alexcrichton's design ofspawn_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 withtask::yield_now
out of the box.Example
Note:
task::sleep
does implementSend
, but it was an easy example to use.The text was updated successfully, but these errors were encountered: