File tree Expand file tree Collapse file tree 8 files changed +23
-16
lines changed Expand file tree Collapse file tree 8 files changed +23
-16
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use std::time::Duration;
55use pin_project_lite:: pin_project;
66
77use crate :: task:: { Context , Poll } ;
8- use crate :: utils:: Timer ;
8+ use crate :: utils:: { timer_after , Timer } ;
99
1010pin_project ! {
1111 #[ doc( hidden) ]
@@ -20,7 +20,7 @@ pin_project! {
2020
2121impl < F > DelayFuture < F > {
2222 pub fn new ( future : F , dur : Duration ) -> DelayFuture < F > {
23- let delay = Timer :: after ( dur) ;
23+ let delay = timer_after ( dur) ;
2424
2525 DelayFuture { future, delay }
2626 }
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ use std::time::Duration;
77use pin_project_lite:: pin_project;
88
99use crate :: task:: { Context , Poll } ;
10- use crate :: utils:: Timer ;
10+ use crate :: utils:: { timer_after , Timer } ;
1111
1212/// Awaits a future or times out after a duration of time.
1313///
@@ -51,7 +51,7 @@ impl<F> TimeoutFuture<F> {
5151 pub ( super ) fn new ( future : F , dur : Duration ) -> TimeoutFuture < F > {
5252 TimeoutFuture {
5353 future,
54- delay : Timer :: after ( dur) ,
54+ delay : timer_after ( dur) ,
5555 }
5656 }
5757}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ use std::time::Duration;
66use pin_project_lite:: pin_project;
77
88use crate :: io;
9- use crate :: utils:: Timer ;
9+ use crate :: utils:: { timer_after , Timer } ;
1010
1111/// Awaits an I/O future or times out after a duration of time.
1212///
3737 F : Future < Output = io:: Result < T > > ,
3838{
3939 Timeout {
40- timeout : Timer :: after ( dur) ,
40+ timeout : timer_after ( dur) ,
4141 future : f,
4242 }
4343 . await
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use std::task::{Context, Poll};
44use std:: time:: Duration ;
55
66use crate :: stream:: Stream ;
7- use crate :: utils:: Timer ;
7+ use crate :: utils:: { timer_after , Timer } ;
88
99/// Creates a new stream that yields at a set interval.
1010///
@@ -45,7 +45,7 @@ use crate::utils::Timer;
4545#[ cfg_attr( feature = "docs" , doc( cfg( unstable) ) ) ]
4646pub fn interval ( dur : Duration ) -> Interval {
4747 Interval {
48- delay : Timer :: after ( dur) ,
48+ delay : timer_after ( dur) ,
4949 interval : dur,
5050 }
5151}
@@ -72,7 +72,7 @@ impl Stream for Interval {
7272 return Poll :: Pending ;
7373 }
7474 let interval = self . interval ;
75- let _ = std:: mem:: replace ( & mut self . delay , Timer :: after ( interval) ) ;
75+ let _ = std:: mem:: replace ( & mut self . delay , timer_after ( interval) ) ;
7676 Poll :: Ready ( Some ( ( ) ) )
7777 }
7878}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ use pin_project_lite::pin_project;
66
77use crate :: stream:: Stream ;
88use crate :: task:: { Context , Poll } ;
9- use crate :: utils:: Timer ;
9+ use crate :: utils:: { timer_after , Timer } ;
1010
1111pin_project ! {
1212 #[ doc( hidden) ]
@@ -24,7 +24,7 @@ impl<S> Delay<S> {
2424 pub ( super ) fn new ( stream : S , dur : Duration ) -> Self {
2525 Delay {
2626 stream,
27- delay : Timer :: after ( dur) ,
27+ delay : timer_after ( dur) ,
2828 delay_done : false ,
2929 }
3030 }
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ use pin_project_lite::pin_project;
66
77use crate :: stream:: Stream ;
88use crate :: task:: { Context , Poll } ;
9- use crate :: utils:: Timer ;
9+ use crate :: utils:: { timer_after , Timer } ;
1010
1111pin_project ! {
1212 /// A stream that only yields one element once every `duration`.
@@ -35,7 +35,7 @@ impl<S: Stream> Throttle<S> {
3535 stream,
3636 duration,
3737 blocked : false ,
38- delay : Timer :: after ( Duration :: default ( ) ) ,
38+ delay : timer_after ( Duration :: default ( ) ) ,
3939 }
4040 }
4141}
@@ -59,7 +59,7 @@ impl<S: Stream> Stream for Throttle<S> {
5959 Poll :: Ready ( None ) => Poll :: Ready ( None ) ,
6060 Poll :: Ready ( Some ( v) ) => {
6161 * this. blocked = true ;
62- let _ = std:: mem:: replace ( & mut * this. delay , Timer :: after ( * this. duration ) ) ;
62+ let _ = std:: mem:: replace ( & mut * this. delay , timer_after ( * this. duration ) ) ;
6363 Poll :: Ready ( Some ( v) )
6464 }
6565 }
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ use pin_project_lite::pin_project;
88
99use crate :: stream:: Stream ;
1010use crate :: task:: { Context , Poll } ;
11- use crate :: utils:: Timer ;
11+ use crate :: utils:: { timer_after , Timer } ;
1212
1313pin_project ! {
1414 /// A stream with timeout time set
@@ -23,7 +23,7 @@ pin_project! {
2323
2424impl < S : Stream > Timeout < S > {
2525 pub ( crate ) fn new ( stream : S , dur : Duration ) -> Self {
26- let delay = Timer :: after ( dur) ;
26+ let delay = timer_after ( dur) ;
2727
2828 Self { stream, delay }
2929 }
Original file line number Diff line number Diff line change @@ -64,6 +64,13 @@ mod timer {
6464 pub type Timer = smol:: Timer ;
6565}
6666
67+ pub ( crate ) fn timer_after ( dur : std:: time:: Duration ) -> timer:: Timer {
68+ #[ cfg( not( target_os = "unknown" ) ) ]
69+ once_cell:: sync:: Lazy :: force ( & crate :: rt:: RUNTIME ) ;
70+
71+ Timer :: after ( dur)
72+ }
73+
6774#[ cfg( any(
6875 all( target_arch = "wasm32" , feature = "default" ) ,
6976 all( feature = "unstable" , not( feature = "default" ) )
You can’t perform that action at this time.
0 commit comments