cdk_common/task.rs
1//! Thin wrapper for spawn and spawn_local for native and wasm.
2
3use std::future::Future;
4
5use tokio::task::JoinHandle;
6
7/// Spawns a new asynchronous task returning nothing
8#[cfg(not(target_arch = "wasm32"))]
9pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
10where
11 F: Future + Send + 'static,
12 F::Output: Send + 'static,
13{
14 tokio::spawn(future)
15}
16
17/// Spawns a new asynchronous task returning nothing
18#[cfg(target_arch = "wasm32")]
19pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
20where
21 F: Future + 'static,
22 F::Output: 'static,
23{
24 tokio::task::spawn_local(future)
25}