-
Hi everybody: I want to add the spawn handle in a I defined as follow: let handle: JoinHandle<Send + 'static> = tokio::task::spawn(async move {
loop {
// do something
// no return data
}
}); The compiler remind me: handles_map: HashMap<String, Arc<JoinHandle<Send + 'static>>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn std::marker::Send + 'static)`
note: required by a bound in `tokio::task::JoinHandle`
--> /home/yanfeng/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.13.0/src/runtime/task/join.rs:144:27
|
144 | pub struct JoinHandle<T> {
| ^ required by this bound in `tokio::task::JoinHandle`
error[E0277]: the size for values of type `(dyn std::marker::Send + 'static)` cannot be known at compilation time
How to define the JoinHandle<<???>> in |
Beta Was this translation helpful? Give feedback.
Answered by
Darksonn
Nov 26, 2021
Replies: 1 comment 1 reply
-
The generic parameter in a (It doesn't work when you put |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
hawkw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The generic parameter in a
JoinHandle
is the return type of the task. It is()
for tasks that don't return anything. If you don't know what the return type is, you can put any type in the spot and the compiler error will tell you what to put instead.(It doesn't work when you put
Send
, but that's becauseSend
is not a type — it's a trait.)