ev3dev_rs/tools.rs
1use std::time::Duration;
2use tokio::time::sleep;
3
4/// A pybricks-like async wait function.
5pub async fn wait(duration: Duration) {
6 sleep(duration).await;
7}
8
9/// A non-racing multitasker.
10///
11/// # Examples
12/// ```
13/// use ev3dev_rs::join;
14/// join!(drive.straight(100), attachment_motor.run_until_stalled(-45))?;
15/// ```
16#[macro_export]
17macro_rules! join {
18 ($($fut:expr),+ $(,)?) => {
19 tokio::try_join!($($fut),+)
20 };
21}
22
23/// A racing multitasker
24///
25/// # Examples
26/// ```
27/// use ev3dev_rs::select;
28/// select!(drive.straight(100), attachment_motor.run_until_stalled(-45))?;
29/// ```
30#[macro_export]
31macro_rules! select {
32 ($($fut:expr),+ $(,)?) => {
33 ev3dev_rs::Race::race(($($fut),+)).await
34 };
35}