Merge #1260
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:
		| @@ -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 | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user