aboutsummaryrefslogtreecommitdiff
path: root/embassy-time
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-04-26 23:18:28 +0200
committerDario Nieuwenhuis <[email protected]>2024-04-26 23:22:25 +0200
commit5732ee7ca975c0dd1afa83ade1667a2599d20985 (patch)
treef627117733d3fcd5bbb4eb664559c387a8e81f33 /embassy-time
parent597315873dbef394ae4cefe0af740fcb1bb951e0 (diff)
Reduce use of the full `futures` crate.
Diffstat (limited to 'embassy-time')
-rw-r--r--embassy-time/src/timer.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs
index 757c3ff00..bc39d8bc7 100644
--- a/embassy-time/src/timer.rs
+++ b/embassy-time/src/timer.rs
@@ -1,10 +1,10 @@
1use core::future::{poll_fn, Future}; 1use core::future::{poll_fn, Future};
2use core::pin::Pin; 2use core::pin::{pin, Pin};
3use core::task::{Context, Poll}; 3use core::task::{Context, Poll};
4 4
5use futures_util::future::{select, Either}; 5use futures_util::future::{select, Either};
6use futures_util::stream::FusedStream; 6use futures_util::stream::FusedStream;
7use futures_util::{pin_mut, Stream}; 7use futures_util::Stream;
8 8
9use crate::{Duration, Instant}; 9use crate::{Duration, Instant};
10 10
@@ -19,8 +19,7 @@ pub struct TimeoutError;
19/// work on the future is stopped (`poll` is no longer called), the future is dropped and `Err(TimeoutError)` is returned. 19/// work on the future is stopped (`poll` is no longer called), the future is dropped and `Err(TimeoutError)` is returned.
20pub async fn with_timeout<F: Future>(timeout: Duration, fut: F) -> Result<F::Output, TimeoutError> { 20pub async fn with_timeout<F: Future>(timeout: Duration, fut: F) -> Result<F::Output, TimeoutError> {
21 let timeout_fut = Timer::after(timeout); 21 let timeout_fut = Timer::after(timeout);
22 pin_mut!(fut); 22 match select(pin!(fut), timeout_fut).await {
23 match select(fut, timeout_fut).await {
24 Either::Left((r, _)) => Ok(r), 23 Either::Left((r, _)) => Ok(r),
25 Either::Right(_) => Err(TimeoutError), 24 Either::Right(_) => Err(TimeoutError),
26 } 25 }
@@ -32,8 +31,7 @@ pub async fn with_timeout<F: Future>(timeout: Duration, fut: F) -> Result<F::Out
32/// work on the future is stopped (`poll` is no longer called), the future is dropped and `Err(TimeoutError)` is returned. 31/// work on the future is stopped (`poll` is no longer called), the future is dropped and `Err(TimeoutError)` is returned.
33pub async fn with_deadline<F: Future>(at: Instant, fut: F) -> Result<F::Output, TimeoutError> { 32pub async fn with_deadline<F: Future>(at: Instant, fut: F) -> Result<F::Output, TimeoutError> {
34 let timeout_fut = Timer::at(at); 33 let timeout_fut = Timer::at(at);
35 pin_mut!(fut); 34 match select(pin!(fut), timeout_fut).await {
36 match select(fut, timeout_fut).await {
37 Either::Left((r, _)) => Ok(r), 35 Either::Left((r, _)) => Ok(r),
38 Either::Right(_) => Err(TimeoutError), 36 Either::Right(_) => Err(TimeoutError),
39 } 37 }