Skip to main content

moire_tokio/disabled/task/
mod.rs

1pub use join_handle::JoinHandle;
2pub use joinset::JoinSet;
3
4pub mod join_handle;
5pub mod joinset;
6
7use std::future::IntoFuture;
8
9/// No-op extension trait matching the enabled `FutureExt`.
10pub trait FutureExt: IntoFuture + Sized {
11    fn named(self, _name: impl Into<String>) -> Self {
12        self
13    }
14}
15
16impl<F: IntoFuture + Sized> FutureExt for F {}
17
18/// Spawns a task, equivalent to [`tokio::task::spawn`].
19pub fn spawn<T, F>(future: F) -> JoinHandle<T>
20where
21    T: Send + 'static,
22    F: Future<Output = T> + Send + 'static,
23{
24    JoinHandle(tokio::task::spawn(future))
25}
26
27/// Spawns a blocking task, equivalent to [`tokio::task::spawn_blocking`].
28pub fn spawn_blocking<T, F>(f: F) -> JoinHandle<T>
29where
30    T: Send + 'static,
31    F: FnOnce() -> T + Send + 'static,
32{
33    JoinHandle(tokio::task::spawn_blocking(f))
34}