@@ -12,6 +12,7 @@ use futures_util::stream::StreamExt;
12
12
use std:: marker:: Unpin ;
13
13
use std:: pin;
14
14
use std:: pin:: Pin ;
15
+ use std:: time:: Duration ;
15
16
16
17
use Continue ;
17
18
use MainContext ;
@@ -108,7 +109,7 @@ impl<T, F> Drop for SourceFuture<T, F> {
108
109
/// Create a `Future` that will resolve after the given number of milliseconds.
109
110
///
110
111
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
111
- pub fn timeout_future ( value : u32 ) -> Pin < Box < dyn Future < Output = ( ) > + Send + ' static > > {
112
+ pub fn timeout_future ( value : Duration ) -> Pin < Box < dyn Future < Output = ( ) > + Send + ' static > > {
112
113
timeout_future_with_priority ( :: PRIORITY_DEFAULT , value)
113
114
}
114
115
@@ -117,7 +118,7 @@ pub fn timeout_future(value: u32) -> Pin<Box<dyn Future<Output = ()> + Send + 's
117
118
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
118
119
pub fn timeout_future_with_priority (
119
120
priority : Priority ,
120
- value : u32 ,
121
+ value : Duration ,
121
122
) -> Pin < Box < dyn Future < Output = ( ) > + Send + ' static > > {
122
123
Box :: pin ( SourceFuture :: new ( move |send| {
123
124
let mut send = Some ( send) ;
@@ -295,7 +296,7 @@ impl<T, F> Drop for SourceStream<T, F> {
295
296
/// Create a `Stream` that will provide a value every given number of milliseconds.
296
297
///
297
298
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
298
- pub fn interval_stream ( value : u32 ) -> Pin < Box < dyn Stream < Item = ( ) > + Send + ' static > > {
299
+ pub fn interval_stream ( value : Duration ) -> Pin < Box < dyn Stream < Item = ( ) > + Send + ' static > > {
299
300
interval_stream_with_priority ( :: PRIORITY_DEFAULT , value)
300
301
}
301
302
@@ -304,7 +305,7 @@ pub fn interval_stream(value: u32) -> Pin<Box<dyn Stream<Item = ()> + Send + 'st
304
305
/// The `Future` must be spawned on an `Executor` backed by a `glib::MainContext`.
305
306
pub fn interval_stream_with_priority (
306
307
priority : Priority ,
307
- value : u32 ,
308
+ value : Duration ,
308
309
) -> Pin < Box < dyn Stream < Item = ( ) > + Send + ' static > > {
309
310
Box :: pin ( SourceStream :: new ( move |send| {
310
311
:: timeout_source_new ( value, None , priority, move || {
@@ -372,13 +373,14 @@ pub fn unix_signal_stream_with_priority(
372
373
#[ cfg( test) ]
373
374
mod tests {
374
375
use super :: * ;
376
+ use std:: time:: Duration ;
375
377
use std:: thread;
376
378
377
379
#[ test]
378
380
fn test_timeout ( ) {
379
381
let c = MainContext :: new ( ) ;
380
382
381
- c. block_on ( timeout_future ( 20 ) ) ;
383
+ c. block_on ( timeout_future ( Duration :: from_millis ( 20 ) ) ) ;
382
384
}
383
385
384
386
#[ test]
@@ -387,7 +389,7 @@ mod tests {
387
389
let l = :: MainLoop :: new ( Some ( & c) , false ) ;
388
390
389
391
let l_clone = l. clone ( ) ;
390
- c. spawn ( timeout_future ( 20 ) . then ( move |( ) | {
392
+ c. spawn ( timeout_future ( Duration :: from_millis ( 20 ) ) . then ( move |( ) | {
391
393
l_clone. quit ( ) ;
392
394
futures_util:: future:: ready ( ( ) )
393
395
} ) ) ;
@@ -404,7 +406,7 @@ mod tests {
404
406
{
405
407
let count = & mut count;
406
408
c. block_on (
407
- interval_stream ( 20 )
409
+ interval_stream ( Duration :: from_millis ( 20 ) )
408
410
. take ( 2 )
409
411
. for_each ( |( ) | {
410
412
* count += 1 ;
@@ -422,7 +424,7 @@ mod tests {
422
424
fn test_timeout_and_channel ( ) {
423
425
let c = MainContext :: default ( ) ;
424
426
425
- let res = c. block_on ( timeout_future ( 20 ) . then ( |( ) | {
427
+ let res = c. block_on ( timeout_future ( Duration :: from_millis ( 20 ) ) . then ( |( ) | {
426
428
let ( sender, receiver) = oneshot:: channel ( ) ;
427
429
428
430
thread:: spawn ( move || {
0 commit comments