Skip to content

Changing to use web-sys; this fixes a Webpack error #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions crates/timers/src/callback.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Callback-style timer APIs.

use super::sys::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::window;

/// A scheduled timeout.
///
Expand All @@ -20,7 +20,9 @@ pub struct Timeout {
impl Drop for Timeout {
fn drop(&mut self) {
if let Some(id) = self.id {
clear_timeout(id);
window()
.unwrap_throw()
.clear_timeout_with_handle(id);
}
}
}
Expand All @@ -44,10 +46,13 @@ impl Timeout {
{
let closure = Closure::once(callback);

let id = set_timeout(
closure.as_ref().unchecked_ref::<js_sys::Function>(),
millis as i32,
);
let id = window()
.unwrap_throw()
.set_timeout_with_callback_and_timeout_and_arguments_0(
closure.as_ref().unchecked_ref::<js_sys::Function>(),
millis as i32
)
.unwrap_throw();

Timeout {
id: Some(id),
Expand Down Expand Up @@ -102,6 +107,7 @@ impl Timeout {
self.closure.take().unwrap_throw()
}
}

/// A scheduled interval.
///
/// See `Interval::new` for scheduling new intervals.
Expand All @@ -118,7 +124,9 @@ pub struct Interval {
impl Drop for Interval {
fn drop(&mut self) {
if let Some(id) = self.id {
clear_interval(id);
window()
.unwrap_throw()
.clear_interval_with_handle(id);
}
}
}
Expand All @@ -141,10 +149,13 @@ impl Interval {
{
let closure = Closure::wrap(Box::new(callback) as Box<dyn FnMut()>);

let id = set_interval(
closure.as_ref().unchecked_ref::<js_sys::Function>(),
millis as i32,
);
let id = window()
.unwrap_throw()
.set_interval_with_callback_and_timeout_and_arguments_0(
closure.as_ref().unchecked_ref::<js_sys::Function>(),
millis as i32,
)
.unwrap_throw();

Interval {
id: Some(id),
Expand Down
2 changes: 0 additions & 2 deletions crates/timers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,3 @@ pub mod callback;

#[cfg(feature = "futures")]
pub mod future;

mod sys;
20 changes: 0 additions & 20 deletions crates/timers/src/sys.rs

This file was deleted.