1use std::{fmt, future::Future, time::Instant};
2
3pub use crate::handle::{JoinHandle, RemoteJoinHandle};
4pub use crate::{rt::Handle, rt::Runtime};
5
6#[derive(Debug, Copy, Clone)]
7pub struct JoinError;
8
9impl fmt::Display for JoinError {
10 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11 write!(f, "JoinError")
12 }
13}
14
15impl std::error::Error for JoinError {}
16
17#[inline]
22pub fn now() -> Instant {
23 crate::rt::Runtime::current_now()
24}
25
26#[track_caller]
27pub fn spawn<F>(fut: F) -> JoinHandle<F::Output>
28where
29 F: Future + 'static,
30{
31 let location = std::panic::Location::caller();
32 let fut = crate::task::wrap(fut);
33 crate::rt::Runtime::with_current(|rt| unsafe { rt.spawn_at(fut, location) })
34}
35
36#[track_caller]
45pub fn spawn_detached<F>(fut: F)
46where
47 F: Future + 'static,
48{
49 let location = std::panic::Location::caller();
50 let fut = crate::task::wrap(fut);
51 crate::rt::Runtime::with_current(|rt| unsafe { rt.spawn_detached_at(fut, location) });
52}