1260: time/ticker: make sure the future for .next() is Unpin. r=Dirbaio a=Dirbaio

It was Unpin before #1248 

bors r+

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
bors[bot] 2023-03-05 22:15:14 +00:00 committed by GitHub
commit 403a83e08d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,9 @@
use core::future::Future; use core::future::{poll_fn, Future};
use core::pin::Pin; use core::pin::Pin;
use core::task::{Context, Poll, Waker}; use core::task::{Context, Poll, Waker};
use futures_util::future::{select, Either}; use futures_util::future::{select, Either};
use futures_util::{pin_mut, Stream, StreamExt}; use futures_util::{pin_mut, Stream};
use crate::{Duration, Instant}; use crate::{Duration, Instant};
@ -134,8 +134,17 @@ impl Ticker {
} }
/// Waits for the next tick /// Waits for the next tick
pub async fn next(&mut self) { pub fn next(&mut self) -> impl Future<Output = ()> + '_ {
<Self as StreamExt>::next(self).await; poll_fn(|cx| {
if self.expires_at <= Instant::now() {
let dur = self.duration;
self.expires_at += dur;
Poll::Ready(())
} else {
schedule_wake(self.expires_at, cx.waker());
Poll::Pending
}
})
} }
} }