Skip to content

Commit ddb46bc

Browse files
authored
Merge pull request #103 from Pauan/fixing-webpack-errors
Changing to use web-sys; this fixes a Webpack error
2 parents 0ab85a0 + 8a4842a commit ddb46bc

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

crates/timers/src/callback.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Callback-style timer APIs.
22
3-
use super::sys::*;
43
use wasm_bindgen::prelude::*;
54
use wasm_bindgen::JsCast;
5+
use web_sys::window;
66

77
/// A scheduled timeout.
88
///
@@ -20,7 +20,9 @@ pub struct Timeout {
2020
impl Drop for Timeout {
2121
fn drop(&mut self) {
2222
if let Some(id) = self.id {
23-
clear_timeout(id);
23+
window()
24+
.unwrap_throw()
25+
.clear_timeout_with_handle(id);
2426
}
2527
}
2628
}
@@ -44,10 +46,13 @@ impl Timeout {
4446
{
4547
let closure = Closure::once(callback);
4648

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();
5156

5257
Timeout {
5358
id: Some(id),
@@ -102,6 +107,7 @@ impl Timeout {
102107
self.closure.take().unwrap_throw()
103108
}
104109
}
110+
105111
/// A scheduled interval.
106112
///
107113
/// See `Interval::new` for scheduling new intervals.
@@ -118,7 +124,9 @@ pub struct Interval {
118124
impl Drop for Interval {
119125
fn drop(&mut self) {
120126
if let Some(id) = self.id {
121-
clear_interval(id);
127+
window()
128+
.unwrap_throw()
129+
.clear_interval_with_handle(id);
122130
}
123131
}
124132
}
@@ -141,10 +149,13 @@ impl Interval {
141149
{
142150
let closure = Closure::wrap(Box::new(callback) as Box<dyn FnMut()>);
143151

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();
148159

149160
Interval {
150161
id: Some(id),

crates/timers/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,3 @@ pub mod callback;
6464

6565
#[cfg(feature = "futures")]
6666
pub mod future;
67-
68-
mod sys;

crates/timers/src/sys.rs

-20
This file was deleted.

0 commit comments

Comments
 (0)