Implement stdweb backend for web platform

This commit is contained in:
Héctor Ramón Jiménez
2019-06-27 00:02:46 +02:00
parent 1596cc5d9e
commit bb285984da
10 changed files with 355 additions and 906 deletions

View File

@@ -0,0 +1,25 @@
use std::time::Duration;
use stdweb::web::{window, IWindowOrWorker, TimeoutHandle};
#[derive(Debug)]
pub struct Timeout {
handle: TimeoutHandle,
}
impl Timeout {
pub fn new<F>(f: F, duration: Duration) -> Timeout
where
F: 'static + FnMut(),
{
Timeout {
handle: window().set_clearable_timeout(f, duration.as_millis() as u32),
}
}
}
impl Drop for Timeout {
fn drop(&mut self) {
let handle = std::mem::replace(&mut self.handle, unsafe { std::mem::uninitialized() });
handle.clear();
}
}