File tree 2 files changed +25
-17
lines changed
2 files changed +25
-17
lines changed Original file line number Diff line number Diff line change 1
1
//! Callback-style timer APIs.
2
2
3
- use super :: window ;
3
+ use super :: { clear_interval , clear_timeout , set_interval , set_timeout } ;
4
4
use std:: fmt;
5
5
use wasm_bindgen:: prelude:: * ;
6
6
use wasm_bindgen:: JsCast ;
@@ -20,7 +20,7 @@ pub struct Timeout {
20
20
impl Drop for Timeout {
21
21
fn drop ( & mut self ) {
22
22
if let Some ( id) = self . id {
23
- window ( ) . clear_timeout_with_handle ( id) ;
23
+ clear_timeout ( id) ;
24
24
}
25
25
}
26
26
}
@@ -50,12 +50,10 @@ impl Timeout {
50
50
{
51
51
let closure = Closure :: once ( callback) ;
52
52
53
- let id = window ( )
54
- . set_timeout_with_callback_and_timeout_and_arguments_0 (
55
- closure. as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
56
- millis as i32 ,
57
- )
58
- . unwrap_throw ( ) ;
53
+ let id = set_timeout (
54
+ closure. as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
55
+ millis as i32 ,
56
+ ) ;
59
57
60
58
Timeout {
61
59
id : Some ( id) ,
@@ -125,7 +123,7 @@ pub struct Interval {
125
123
impl Drop for Interval {
126
124
fn drop ( & mut self ) {
127
125
if let Some ( id) = self . id {
128
- window ( ) . clear_interval_with_handle ( id) ;
126
+ clear_interval ( id) ;
129
127
}
130
128
}
131
129
}
@@ -158,12 +156,10 @@ impl Interval {
158
156
callback ( ) ;
159
157
} ) as Box < FnMut ( ) > ) ;
160
158
161
- let id = window ( )
162
- . set_interval_with_callback_and_timeout_and_arguments_0 (
163
- closure. as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
164
- millis as i32 ,
165
- )
166
- . unwrap_throw ( ) ;
159
+ let id = set_interval (
160
+ closure. as_ref ( ) . unchecked_ref :: < js_sys:: Function > ( ) ,
161
+ millis as i32 ,
162
+ ) ;
167
163
168
164
Interval {
169
165
id : Some ( id) ,
Original file line number Diff line number Diff line change 67
67
#[ cfg( feature = "futures" ) ]
68
68
extern crate futures_rs as futures;
69
69
70
+ use js_sys:: Function ;
70
71
use wasm_bindgen:: prelude:: * ;
71
72
72
- fn window ( ) -> web_sys:: Window {
73
- web_sys:: window ( ) . unwrap_throw ( )
73
+ #[ wasm_bindgen]
74
+ extern "C" {
75
+ #[ wasm_bindgen( js_name = "setTimeout" ) ]
76
+ pub fn set_timeout ( handler : & Function , timeout : i32 ) -> i32 ;
77
+
78
+ #[ wasm_bindgen( js_name = "clearTimeout" ) ]
79
+ pub fn clear_timeout ( token : i32 ) ;
80
+
81
+ #[ wasm_bindgen( js_name = "setInterval" ) ]
82
+ pub fn set_interval ( handler : & Function , timeout : i32 ) -> i32 ;
83
+
84
+ #[ wasm_bindgen( js_name = "clearInterval" ) ]
85
+ pub fn clear_interval ( token : i32 ) ;
74
86
}
75
87
76
88
pub mod callback;
You can’t perform that action at this time.
0 commit comments