-
Notifications
You must be signed in to change notification settings - Fork 341
Open
Description
Hello,
I'm posting this idea to many Rust async runtimes discussion threads in order to push for the alternative design of the task spawn API described by @matklad in https://matklad.github.io/2023/12/10/nsfw.html
// std::thread::spawn
pub fn spawn<F, T>(f: F) -> JoinHandle<T>
where
F: FnOnce() -> T + Send + 'static,
T: Send + 'static {}
// A hypothetical better async spawn
pub fn spawn<F, Fut>(f: F) -> JoinHandle<Fut::Output>
where
F: FnOnce() -> Fut + Send + 'static,
Fut: Future,
Fut::Output: Send + 'static {}
If you think that this is the right direction for rust to take, I suggest to do the following to arrive at the destination ASAP:
- change task spawn definition to one that takes a closure returning a future
- Provide a safe executor constructor that pins tasks to threads
- Make workstealing executors unsafe to construct... until the language developers "fix" this issue of entangling of Send with OS threads
What do you think?
Metadata
Metadata
Assignees
Labels
No labels