1
1
//! Callback-style timer APIs.
2
2
3
- use super :: sys:: * ;
4
3
use wasm_bindgen:: prelude:: * ;
5
4
use wasm_bindgen:: JsCast ;
5
+ use web_sys:: window;
6
6
7
7
/// A scheduled timeout.
8
8
///
@@ -20,7 +20,9 @@ pub struct Timeout {
20
20
impl Drop for Timeout {
21
21
fn drop ( & mut self ) {
22
22
if let Some ( id) = self . id {
23
- clear_timeout ( id) ;
23
+ window ( )
24
+ . unwrap_throw ( )
25
+ . clear_timeout_with_handle ( id) ;
24
26
}
25
27
}
26
28
}
@@ -44,10 +46,13 @@ impl Timeout {
44
46
{
45
47
let closure = Closure :: once ( callback) ;
46
48
47
- let id = set_timeout (
48
- closure. as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
49
- millis as i32 ,
50
- ) ;
49
+ let id = window ( )
50
+ . unwrap_throw ( )
51
+ . set_timeout_with_callback_and_timeout_and_arguments_0 (
52
+ closure. as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
53
+ millis as i32
54
+ )
55
+ . unwrap_throw ( ) ;
51
56
52
57
Timeout {
53
58
id : Some ( id) ,
@@ -102,6 +107,7 @@ impl Timeout {
102
107
self . closure . take ( ) . unwrap_throw ( )
103
108
}
104
109
}
110
+
105
111
/// A scheduled interval.
106
112
///
107
113
/// See `Interval::new` for scheduling new intervals.
@@ -118,7 +124,9 @@ pub struct Interval {
118
124
impl Drop for Interval {
119
125
fn drop ( & mut self ) {
120
126
if let Some ( id) = self . id {
121
- clear_interval ( id) ;
127
+ window ( )
128
+ . unwrap_throw ( )
129
+ . clear_interval_with_handle ( id) ;
122
130
}
123
131
}
124
132
}
@@ -141,10 +149,13 @@ impl Interval {
141
149
{
142
150
let closure = Closure :: wrap ( Box :: new ( callback) as Box < dyn FnMut ( ) > ) ;
143
151
144
- let id = set_interval (
145
- closure. as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
146
- millis as i32 ,
147
- ) ;
152
+ let id = window ( )
153
+ . unwrap_throw ( )
154
+ . set_interval_with_callback_and_timeout_and_arguments_0 (
155
+ closure. as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
156
+ millis as i32 ,
157
+ )
158
+ . unwrap_throw ( ) ;
148
159
149
160
Interval {
150
161
id : Some ( id) ,
0 commit comments