aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaleb Jamison <[email protected]>2024-01-31 16:26:11 -0500
committerCaleb Jamison <[email protected]>2024-01-31 16:26:11 -0500
commit8b7d85619537fc20ad7ad533433d84ba4975ddc4 (patch)
tree9ec05b932f1bcfb9d4d4f768654637320bb87b44
parent1e698af05bc6e7e520d3f35ef661f34ea6ea359e (diff)
Rename timeout_at to with_deadline
-rw-r--r--embassy-time/src/lib.rs2
-rw-r--r--embassy-time/src/timer.rs2
-rw-r--r--examples/rp/src/bin/debounce.rs6
3 files changed, 5 insertions, 5 deletions
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs
index e7efce49c..3c8575ee9 100644
--- a/embassy-time/src/lib.rs
+++ b/embassy-time/src/lib.rs
@@ -32,7 +32,7 @@ pub use delay::{block_for, Delay};
32pub use duration::Duration; 32pub use duration::Duration;
33pub use embassy_time_driver::TICK_HZ; 33pub use embassy_time_driver::TICK_HZ;
34pub use instant::Instant; 34pub use instant::Instant;
35pub use timer::{timeout_at, with_timeout, Ticker, TimeoutError, Timer}; 35pub use timer::{with_deadline, with_timeout, Ticker, TimeoutError, Timer};
36 36
37const fn gcd(a: u64, b: u64) -> u64 { 37const fn gcd(a: u64, b: u64) -> u64 {
38 if b == 0 { 38 if b == 0 {
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs
index dbce9297c..bcd6bf4f7 100644
--- a/embassy-time/src/timer.rs
+++ b/embassy-time/src/timer.rs
@@ -30,7 +30,7 @@ pub async fn with_timeout<F: Future>(timeout: Duration, fut: F) -> Result<F::Out
30/// 30///
31/// If the future completes before the deadline, its output is returned. Otherwise, on timeout, 31/// If the future completes before the deadline, its output is returned. Otherwise, on timeout,
32/// work on the future is stopped (`poll` is no longer called), the future is dropped and `Err(TimeoutError)` is returned. 32/// work on the future is stopped (`poll` is no longer called), the future is dropped and `Err(TimeoutError)` is returned.
33pub async fn timeout_at<F: Future>(at: Instant, fut: F) -> Result<F::Output, TimeoutError> { 33pub async fn with_deadline<F: Future>(at: Instant, fut: F) -> Result<F::Output, TimeoutError> {
34 let timeout_fut = Timer::at(at); 34 let timeout_fut = Timer::at(at);
35 pin_mut!(fut); 35 pin_mut!(fut);
36 match select(fut, timeout_fut).await { 36 match select(fut, timeout_fut).await {
diff --git a/examples/rp/src/bin/debounce.rs b/examples/rp/src/bin/debounce.rs
index bf1579091..0077f19fc 100644
--- a/examples/rp/src/bin/debounce.rs
+++ b/examples/rp/src/bin/debounce.rs
@@ -7,7 +7,7 @@
7use defmt::info; 7use defmt::info;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_rp::gpio::{Input, Level, Pull}; 9use embassy_rp::gpio::{Input, Level, Pull};
10use embassy_time::{timeout_at, Duration, Instant, Timer}; 10use embassy_time::{with_deadline, Duration, Instant, Timer};
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13pub struct Debouncer<'a> { 13pub struct Debouncer<'a> {
@@ -49,7 +49,7 @@ async fn main(_spawner: Spawner) {
49 let start = Instant::now(); 49 let start = Instant::now();
50 info!("Button Press"); 50 info!("Button Press");
51 51
52 match timeout_at(start + Duration::from_secs(1), btn.debounce()).await { 52 match with_deadline(start + Duration::from_secs(1), btn.debounce()).await {
53 // Button Released < 1s 53 // Button Released < 1s
54 Ok(_) => { 54 Ok(_) => {
55 info!("Button pressed for: {}ms", start.elapsed().as_millis()); 55 info!("Button pressed for: {}ms", start.elapsed().as_millis());
@@ -61,7 +61,7 @@ async fn main(_spawner: Spawner) {
61 } 61 }
62 } 62 }
63 63
64 match timeout_at(start + Duration::from_secs(5), btn.debounce()).await { 64 match with_deadline(start + Duration::from_secs(5), btn.debounce()).await {
65 // Button released <5s 65 // Button released <5s
66 Ok(_) => { 66 Ok(_) => {
67 info!("Button pressed for: {}ms", start.elapsed().as_millis()); 67 info!("Button pressed for: {}ms", start.elapsed().as_millis());