vexide_async/
lib.rs

1//! Tiny async runtime for `vexide`.
2//!
3//! This crate contains an implementation of vexide's async executor, which is driven by `smol`'s
4//! [`async_task`] crate. The executor is optimized for use on VEXos-based systems and supports
5//! spawning tasks and blocking on futures. It has a reactor to improve the performance of some
6//! futures (such as [`Sleep`](crate::time::Sleep)).
7
8mod executor;
9mod reactor;
10
11mod local;
12pub mod task;
13pub mod time;
14
15use core::future::Future;
16
17pub use task::spawn;
18
19use crate::executor::EXECUTOR;
20
21/// Synchronization primitives for async code.
22///
23/// vexide programs often use async [tasks](crate::task) to run multiple operations concurrently.
24/// These primitives provide methods for tasks to safely communicate with each other and share data.
25/// This is vexide's async equivalent to the [`std::sync` module].
26///
27/// [`std::sync` module]: https://doc.rust-lang.org/stable/std/sync/index.html
28#[cfg(feature = "sync")]
29pub mod sync {
30    pub use async_lock::{
31        Barrier, BarrierWaitResult, Mutex, MutexGuard, OnceCell, RwLock, RwLockReadGuard,
32        RwLockWriteGuard,
33    };
34}
35
36/// Blocks the current task until a return value can be extracted from the provided future.
37///
38/// Does not poll all futures to completion.
39pub fn block_on<T>(future: impl Future<Output = T>) -> T {
40    EXECUTOR.with(|ex| ex.block_on(future))
41}