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