1
1
//! `Future`- and `Stream`-backed timers APIs.
2
2
3
- use super :: window ;
3
+ use super :: { clear_interval , clear_timeout , set_interval , set_timeout } ;
4
4
use futures:: prelude:: * ;
5
5
use futures:: sync:: mpsc;
6
6
use std:: fmt;
@@ -56,7 +56,7 @@ pub struct TimeoutFuture {
56
56
impl Drop for TimeoutFuture {
57
57
fn drop ( & mut self ) {
58
58
if let Some ( id) = self . id {
59
- window ( ) . clear_timeout_with_handle ( id) ;
59
+ clear_timeout ( id) ;
60
60
}
61
61
}
62
62
}
@@ -84,11 +84,7 @@ impl TimeoutFuture {
84
84
pub fn new ( millis : u32 ) -> TimeoutFuture {
85
85
let mut id = None ;
86
86
let promise = js_sys:: Promise :: new ( & mut |resolve, _reject| {
87
- id = Some (
88
- window ( )
89
- . set_timeout_with_callback_and_timeout_and_arguments_0 ( & resolve, millis as i32 )
90
- . unwrap_throw ( ) ,
91
- ) ;
87
+ id = Some ( set_timeout ( & resolve, millis as i32 ) ) ;
92
88
} ) ;
93
89
debug_assert ! ( id. is_some( ) ) ;
94
90
let inner = JsFuture :: from ( promise) ;
@@ -173,7 +169,7 @@ impl IntervalStream {
173
169
impl Drop for IntervalStream {
174
170
fn drop ( & mut self ) {
175
171
if let Some ( id) = self . id {
176
- window ( ) . clear_interval_with_handle ( id) ;
172
+ clear_interval ( id) ;
177
173
}
178
174
}
179
175
}
@@ -192,14 +188,10 @@ impl Stream for IntervalStream {
192
188
193
189
fn poll ( & mut self ) -> Poll < Option < ( ) > , ( ) > {
194
190
if self . id . is_none ( ) {
195
- self . id = Some (
196
- window ( )
197
- . set_interval_with_callback_and_timeout_and_arguments_0 (
198
- self . closure . as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
199
- self . millis as i32 ,
200
- )
201
- . unwrap_throw ( ) ,
202
- ) ;
191
+ self . id = Some ( set_interval (
192
+ self . closure . as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
193
+ self . millis as i32 ,
194
+ ) ) ;
203
195
}
204
196
205
197
self . inner . poll ( )
0 commit comments