task/
lib.rs

1#![no_std]
2
3extern crate alloc;
4
5#[cfg(any(test, feature = "std"))]
6extern crate std;
7
8mod environment_variable;
9mod error;
10mod join_handle;
11mod manager;
12mod signal;
13mod task;
14
15use core::time::Duration;
16use embassy_time::Timer;
17
18pub use embassy_executor;
19pub use environment_variable::*;
20pub use error::*;
21pub use join_handle::*;
22pub use manager::*;
23pub use signal::*;
24pub use task::*;
25pub use task_macros::{run, test};
26
27/// Sleep the current thread for a given duration.
28pub async fn sleep(duration: impl Into<Duration>) {
29    let nano_seconds = duration.into().as_nanos();
30
31    Timer::after(embassy_time::Duration::from_nanos(nano_seconds as u64)).await
32}
33
34#[cfg(target_arch = "wasm32")]
35pub async fn yield_now() {
36    sleep(Duration::from_millis(10)).await
37}
38#[cfg(not(target_arch = "wasm32"))]
39pub use embassy_futures::yield_now;
40
41pub fn block_on<F: core::future::Future>(future: F) -> F::Output {
42    embassy_futures::block_on(future)
43}