use std::{
future::Future,
time::{Duration, Instant},
};
pub use edge_executor::Task;
const MAX_NUM_TASKS: usize = 32;
pub type Executor = edge_executor::LocalExecutor<'static, MAX_NUM_TASKS>;
pub fn spawn<F, T>(fut: F) -> Task<T>
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
let ptr = crate::hal::EXECUTOR.load(std::sync::atomic::Ordering::SeqCst);
let executor = unsafe { &*ptr };
executor.spawn(fut)
}
pub async fn sleep(dur: Duration) {
embassy_time::Timer::after(embassy_time::Duration::from_micros(dur.as_micros() as u64)).await;
}
pub async fn sleep_ms(ms: u64) {
sleep(Duration::from_millis(ms)).await;
}
pub async fn sleep_until(t: Instant) {
sleep(t.saturating_duration_since(Instant::now())).await;
}