rsiot/executor/
join_set_spawn.rs1use std::future::Future;
2
3use tokio::task::JoinSet;
4use tracing::error;
5
6#[cfg(feature = "single-thread")]
7pub fn join_set_spawn<F, T>(join_set: &mut JoinSet<T>, name: impl AsRef<str>, task: F)
9where
10 F: Future<Output = T> + 'static,
11 T: Send + 'static,
12{
13 let res = join_set.build_task().name(name.as_ref()).spawn_local(task);
14 if let Err(e) = res {
15 error!("Error spawning task: {}", e);
16 }
17}
18
19#[cfg(not(feature = "single-thread"))]
20pub fn join_set_spawn<F, T>(join_set: &mut JoinSet<T>, name: impl AsRef<str>, task: F)
22where
23 F: Future<Output = T> + Send + 'static,
24 T: Send + 'static,
25{
26 let res = join_set.build_task().name(name.as_ref()).spawn(task);
27
28 if let Err(e) = res {
29 error!("Error spawning task: {}", e);
30 }
31}
32
33pub fn join_set_spawn_blocking<F, T>(join_set: &mut JoinSet<T>, name: impl AsRef<str>, task: F)
35where
36 F: FnOnce() -> T + Send + 'static,
37 T: Send + 'static,
38{
39 let res = join_set
40 .build_task()
41 .name(name.as_ref())
42 .spawn_blocking(task);
43
44 if let Err(e) = res {
45 error!("Error spawning task: {}", e);
46 }
47}