task.rs 593 B

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