diff --git a/Cargo.toml b/Cargo.toml index 68eccafe..8f4e7e55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,8 @@ version = "0.1.0" gloo-timers = { version = "0.1.0", path = "crates/timers" } gloo-console-timer = { version = "0.1.0", path = "crates/console-timer" } +[features] +default = [] +futures = ["gloo-timers/futures"] + [workspace] diff --git a/crates/console-timer/src/lib.rs b/crates/console-timer/src/lib.rs index 4ddeee23..904d965e 100644 --- a/crates/console-timer/src/lib.rs +++ b/crates/console-timer/src/lib.rs @@ -34,7 +34,7 @@ The measurement ends when the timer object goes out of scope / is dropped. ```no_run use gloo_console_timer::ConsoleTimer; -use gloo_timers::Timeout; +use gloo_timers::callback::Timeout; // Start timing a new operation. let timer = ConsoleTimer::new("foo"); diff --git a/crates/timers/Cargo.toml b/crates/timers/Cargo.toml index 3916173c..7b21fc95 100644 --- a/crates/timers/Cargo.toml +++ b/crates/timers/Cargo.toml @@ -5,10 +5,17 @@ authors = ["Rust and WebAssembly Working Group"] edition = "2018" [dependencies] -wasm-bindgen-futures = "0.3.14" wasm-bindgen = "0.2.37" js-sys = "0.3.14" -futures = "0.1.25" + +[dependencies.futures_rs] +package = "futures" +version = "0.1.25" +optional = true + +[dependencies.wasm-bindgen-futures] +version = "0.3.14" +optional = true [dependencies.web-sys] version = "0.3.14" @@ -16,5 +23,10 @@ features = [ "Window", ] +[features] +default = [] +futures = ["futures_rs", "wasm-bindgen-futures"] + + [dev-dependencies] wasm-bindgen-test = "0.2.37" diff --git a/crates/timers/src/lib.rs b/crates/timers/src/lib.rs index 6bc093a3..33ea9ab1 100644 --- a/crates/timers/src/lib.rs +++ b/crates/timers/src/lib.rs @@ -14,7 +14,7 @@ Timeouts fire once after a period of time (measured in milliseconds). ### Timeouts with a Callback Function ```no_run -use gloo_timers::Timeout; +use gloo_timers::callback::Timeout; let timeout = Timeout::new(1_000, move || { // Do something after the one second timeout is up! @@ -26,9 +26,16 @@ timeout.forget(); ### Timeouts as `Future`s -```no_run +With the `futures` feature enabled, a `future` module containing futures-based +timers is exposed. + +*/ +#![cfg_attr(feature = "futures", doc = "```no_run")] +#![cfg_attr(not(feature = "futures"), doc = "```ignore")] +/*! +# extern crate futures_rs as futures; use futures::prelude::*; -use gloo_timers::TimeoutFuture; +use gloo_timers::future::TimeoutFuture; use wasm_bindgen_futures::spawn_local; let timeout = TimeoutFuture::new(1_000).and_then(|_| { @@ -57,429 +64,449 @@ TODO #![deny(missing_docs, missing_debug_implementations)] -use futures::prelude::*; -use futures::sync::mpsc; -use std::fmt; +#[cfg(feature = "futures")] +extern crate futures_rs as futures; + use wasm_bindgen::prelude::*; -use wasm_bindgen::JsCast; -use wasm_bindgen_futures::JsFuture; fn window() -> web_sys::Window { web_sys::window().unwrap_throw() } -/// A scheduled timeout. -/// -/// See `Timeout::new` for scheduling new timeouts. -/// -/// Once scheduled, you can either `cancel` so that it doesn't run or `forget` -/// it so that it is un-cancel-able. -#[must_use = "timeouts cancel on drop; either call `forget` or `drop` explicitly"] -pub struct Timeout { - id: Option, - closure: Option>, -} +/// Callback-style APIs. +pub mod callback { + use super::window; + use std::fmt; + use wasm_bindgen::prelude::*; + use wasm_bindgen::JsCast; + /// A scheduled timeout. + /// + /// See `Timeout::new` for scheduling new timeouts. + /// + /// Once scheduled, you can either `cancel` so that it doesn't run or `forget` + /// it so that it is un-cancel-able. + #[must_use = "timeouts cancel on drop; either call `forget` or `drop` explicitly"] + pub struct Timeout { + id: Option, + closure: Option>, + } -impl Drop for Timeout { - fn drop(&mut self) { - if let Some(id) = self.id { - window().clear_timeout_with_handle(id); + impl Drop for Timeout { + fn drop(&mut self) { + if let Some(id) = self.id { + window().clear_timeout_with_handle(id); + } } } -} -impl fmt::Debug for Timeout { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Timeout").field("id", &self.id).finish() + impl fmt::Debug for Timeout { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Timeout").field("id", &self.id).finish() + } } -} -impl Timeout { - /// Schedule a timeout to invoke `callback` in `millis` milliseconds from - /// now. - /// - /// # Example - /// - /// ```no_run - /// use gloo_timers::Timeout; - /// - /// let timeout = Timeout::new(1_000, move || { - /// // Do something... - /// }); - /// ``` - pub fn new(millis: u32, callback: F) -> Timeout - where - F: 'static + FnOnce(), - { - // TODO: Use `FnOnce` here after this merges: - // https://github.com/rustwasm/wasm-bindgen/pull/1281 - let mut callback = Some(callback); - let closure = Closure::wrap(Box::new(move || { - let callback = callback.take().unwrap_throw(); - callback(); - }) as Box); - - let id = window() - .set_timeout_with_callback_and_timeout_and_arguments_0( - closure.as_ref().unchecked_ref::(), - millis as i32, - ) - .unwrap_throw(); - - Timeout { - id: Some(id), - closure: Some(closure), + impl Timeout { + /// Schedule a timeout to invoke `callback` in `millis` milliseconds from + /// now. + /// + /// # Example + /// + /// ```no_run + /// use gloo_timers::callback::Timeout; + /// + /// let timeout = Timeout::new(1_000, move || { + /// // Do something... + /// }); + /// ``` + pub fn new(millis: u32, callback: F) -> Timeout + where + F: 'static + FnOnce(), + { + // TODO: Use `FnOnce` here after this merges: + // https://github.com/rustwasm/wasm-bindgen/pull/1281 + let mut callback = Some(callback); + let closure = Closure::wrap(Box::new(move || { + let callback = callback.take().unwrap_throw(); + callback(); + }) as Box); + + let id = window() + .set_timeout_with_callback_and_timeout_and_arguments_0( + closure.as_ref().unchecked_ref::(), + millis as i32, + ) + .unwrap_throw(); + + Timeout { + id: Some(id), + closure: Some(closure), + } } - } - /// Make this timeout uncancel-able. - /// - /// Returns the identifier returned by the original `setTimeout` call, and - /// therefore you can still cancel the timeout by calling `clearTimeout` - /// directly (perhaps via `web_sys::clear_timeout_with_handle`). - /// - /// # Example + /// Make this timeout uncancel-able. + /// + /// Returns the identifier returned by the original `setTimeout` call, and + /// therefore you can still cancel the timeout by calling `clearTimeout` + /// directly (perhaps via `web_sys::clear_timeout_with_handle`). + /// + /// # Example + /// + /// ```no_run + /// use gloo_timers::callback::Timeout; + /// + /// // We definitely want to do stuff, and aren't going to ever cancel this + /// // timeout. + /// Timeout::new(1_000, || { + /// // Do stuff... + /// }).forget(); + /// ``` + pub fn forget(mut self) -> i32 { + let id = self.id.take().unwrap_throw(); + self.closure.take().unwrap_throw().forget(); + id + } + + /// Cancel this timeout so that the callback is not invoked after the time + /// is up. + /// + /// The scheduled callback is returned. + /// + /// # Example + /// + /// ```no_run + /// use gloo_timers::callback::Timeout; + /// + /// let timeout = Timeout::new(1_000, || { + /// // Do stuff... + /// }); + /// + /// // If actually we didn't want to set a timer, then cancel it. + /// if nevermind() { + /// timeout.cancel(); + /// } + /// # fn nevermind() -> bool { true } + /// ``` + pub fn cancel(mut self) -> Closure { + self.closure.take().unwrap_throw() + } + } + /// A scheduled interval. /// - /// ```no_run - /// use gloo_timers::Timeout; + /// See `Interval::new` for scheduling new intervals. /// - /// // We definitely want to do stuff, and aren't going to ever cancel this - /// // timeout. - /// Timeout::new(1_000, || { - /// // Do stuff... - /// }).forget(); - /// ``` - pub fn forget(mut self) -> i32 { - let id = self.id.take().unwrap_throw(); - self.closure.take().unwrap_throw().forget(); - id + /// Once scheduled, you can either `cancel` so that it ceases to fire or `forget` + /// it so that it is un-cancel-able. + #[must_use = "intervals cancel on drop; either call `forget` or `drop` explicitly"] + pub struct Interval { + id: Option, + closure: Option>, } - /// Cancel this timeout so that the callback is not invoked after the time - /// is up. - /// - /// The scheduled callback is returned. - /// - /// # Example - /// - /// ```no_run - /// use gloo_timers::Timeout; - /// - /// let timeout = Timeout::new(1_000, || { - /// // Do stuff... - /// }); - /// - /// // If actually we didn't want to set a timer, then cancel it. - /// if nevermind() { - /// timeout.cancel(); - /// } - /// # fn nevermind() -> bool { true } - /// ``` - pub fn cancel(mut self) -> Closure { - self.closure.take().unwrap_throw() + impl Drop for Interval { + fn drop(&mut self) { + if let Some(id) = self.id { + window().clear_interval_with_handle(id); + } + } } -} -/// A scheduled timeout as a `Future`. -/// -/// See `TimeoutFuture::new` for scheduling new timeouts. -/// -/// Once scheduled, if you change your mind and don't want the timeout to fire, -/// you can `drop` the future. -/// -/// A timeout future will never resolve to `Err`. Its only failure mode is when -/// the timeout is so long that it is effectively infinite and never fires. -/// -/// # Example -/// -/// ```no_run -/// use futures::prelude::*; -/// use gloo_timers::TimeoutFuture; -/// -/// let timeout_a = TimeoutFuture::new(1_000).map(|_| "a"); -/// let timeout_b = TimeoutFuture::new(2_000).map(|_| "b"); -/// -/// wasm_bindgen_futures::spawn_local( -/// timeout_a -/// .select(timeout_b) -/// .and_then(|(who, other)| { -/// // `timeout_a` should have won this race. -/// assert_eq!(who, "a"); -/// -/// // Drop `timeout_b` to cancel its timeout. -/// drop(other); -/// -/// Ok(()) -/// }) -/// .map_err(|_| { -/// wasm_bindgen::throw_str( -/// "unreachable -- timeouts never fail, only potentially hang" -/// ); -/// }) -/// ); -/// ``` -#[must_use = "futures do nothing unless polled or spawned"] -pub struct TimeoutFuture { - id: Option, - inner: JsFuture, -} + impl fmt::Debug for Interval { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Interval").field("id", &self.id).finish() + } + } -impl Drop for TimeoutFuture { - fn drop(&mut self) { - if let Some(id) = self.id { - window().clear_timeout_with_handle(id); + impl Interval { + /// Schedule an interval to invoke `callback` every `millis` milliseconds. + /// + /// # Example + /// + /// ```no_run + /// use gloo_timers::callback::Interval; + /// + /// let interval = Interval::new(1_000, move || { + /// // Do something... + /// }); + /// ``` + pub fn new(millis: u32, callback: F) -> Interval + where + F: 'static + FnMut(), + { + let mut callback = Some(callback); + let closure = Closure::wrap(Box::new(move || { + let mut callback = callback.take().unwrap_throw(); + callback(); + }) as Box); + + let id = window() + .set_interval_with_callback_and_timeout_and_arguments_0( + closure.as_ref().unchecked_ref::(), + millis as i32, + ) + .unwrap_throw(); + + Interval { + id: Some(id), + closure: Some(closure), + } + } + + /// Make this interval uncancel-able. + /// + /// Returns the identifier returned by the original `setInterval` call, and + /// therefore you can still cancel the interval by calling `clearInterval` + /// directly (perhaps via `web_sys::clear_interval_with_handle`). + /// + /// # Example + /// + /// ```no_run + /// use gloo_timers::callback::Interval; + /// + /// // We want to do stuff every second, indefinitely. + /// Interval::new(1_000, || { + /// // Do stuff... + /// }).forget(); + /// ``` + pub fn forget(mut self) -> i32 { + let id = self.id.take().unwrap_throw(); + self.closure.take().unwrap_throw().forget(); + id + } + + /// Cancel this interval so that the callback is no longer periodically + /// invoked. + /// + /// The scheduled callback is returned. + /// + /// # Example + /// + /// ```no_run + /// use gloo_timers::callback::Interval; + /// + /// let interval = Interval::new(1_000, || { + /// // Do stuff... + /// }); + /// + /// // If we don't want this interval to run anymore, then cancel it. + /// if nevermind() { + /// interval.cancel(); + /// } + /// # fn nevermind() -> bool { true } + /// ``` + pub fn cancel(mut self) -> Closure { + self.closure.take().unwrap_throw() } } } -impl TimeoutFuture { - /// Create a new timeout future. +/// Future/stream-backed APIs. +#[cfg(feature = "futures")] +pub mod future { + use super::window; + use futures::prelude::*; + use futures::sync::mpsc; + use std::fmt; + use wasm_bindgen::prelude::*; + use wasm_bindgen::JsCast; + use wasm_bindgen_futures::JsFuture; + /// A scheduled timeout as a `Future`. /// - /// Remember that futures do nothing unless polled or spawned, so either - /// pass this future to `wasm_bindgen_futures::spawn_local` or use it inside - /// another future. + /// See `TimeoutFuture::new` for scheduling new timeouts. + /// + /// Once scheduled, if you change your mind and don't want the timeout to fire, + /// you can `drop` the future. + /// + /// A timeout future will never resolve to `Err`. Its only failure mode is when + /// the timeout is so long that it is effectively infinite and never fires. /// /// # Example /// /// ```no_run + /// # extern crate futures_rs as futures; /// use futures::prelude::*; - /// use gloo_timers::TimeoutFuture; + /// use gloo_timers::future::TimeoutFuture; + /// + /// let timeout_a = TimeoutFuture::new(1_000).map(|_| "a"); + /// let timeout_b = TimeoutFuture::new(2_000).map(|_| "b"); /// /// wasm_bindgen_futures::spawn_local( - /// TimeoutFuture::new(1_000).map(|_| { - /// // Do stuff after one second... - /// }) + /// timeout_a + /// .select(timeout_b) + /// .and_then(|(who, other)| { + /// // `timeout_a` should have won this race. + /// assert_eq!(who, "a"); + /// + /// // Drop `timeout_b` to cancel its timeout. + /// drop(other); + /// + /// Ok(()) + /// }) + /// .map_err(|_| { + /// wasm_bindgen::throw_str( + /// "unreachable -- timeouts never fail, only potentially hang" + /// ); + /// }) /// ); /// ``` - pub fn new(millis: u32) -> TimeoutFuture { - let mut id = None; - let promise = js_sys::Promise::new(&mut |resolve, _reject| { - id = Some( - window() - .set_timeout_with_callback_and_timeout_and_arguments_0(&resolve, millis as i32) - .unwrap_throw(), - ); - }); - debug_assert!(id.is_some()); - let inner = JsFuture::from(promise); - TimeoutFuture { id, inner } + #[must_use = "futures do nothing unless polled or spawned"] + pub struct TimeoutFuture { + id: Option, + inner: JsFuture, } -} -impl fmt::Debug for TimeoutFuture { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("TimeoutFuture") - .field("id", &self.id) - .finish() - } -} - -impl Future for TimeoutFuture { - type Item = (); - type Error = (); - - fn poll(&mut self) -> Poll<(), ()> { - match self.inner.poll() { - Ok(Async::Ready(_)) => Ok(Async::Ready(())), - Ok(Async::NotReady) => Ok(Async::NotReady), - // We only ever `resolve` the promise, never reject it. - Err(_) => wasm_bindgen::throw_str("unreachable"), + impl Drop for TimeoutFuture { + fn drop(&mut self) { + if let Some(id) = self.id { + window().clear_timeout_with_handle(id); + } } } -} - -/// A scheduled interval. -/// -/// See `Interval::new` for scheduling new intervals. -/// -/// Once scheduled, you can either `cancel` so that it ceases to fire or `forget` -/// it so that it is un-cancel-able. -#[must_use = "intervals cancel on drop; either call `forget` or `drop` explicitly"] -pub struct Interval { - id: Option, - closure: Option>, -} -impl Drop for Interval { - fn drop(&mut self) { - if let Some(id) = self.id { - window().clear_interval_with_handle(id); + impl TimeoutFuture { + /// Create a new timeout future. + /// + /// Remember that futures do nothing unless polled or spawned, so either + /// pass this future to `wasm_bindgen_futures::spawn_local` or use it inside + /// another future. + /// + /// # Example + /// + /// ```no_run + /// # extern crate futures_rs as futures; + /// use futures::prelude::*; + /// use gloo_timers::future::TimeoutFuture; + /// + /// wasm_bindgen_futures::spawn_local( + /// TimeoutFuture::new(1_000).map(|_| { + /// // Do stuff after one second... + /// }) + /// ); + /// ``` + pub fn new(millis: u32) -> TimeoutFuture { + let mut id = None; + let promise = js_sys::Promise::new(&mut |resolve, _reject| { + id = Some( + window() + .set_timeout_with_callback_and_timeout_and_arguments_0( + &resolve, + millis as i32, + ) + .unwrap_throw(), + ); + }); + debug_assert!(id.is_some()); + let inner = JsFuture::from(promise); + TimeoutFuture { id, inner } } } -} -impl fmt::Debug for Interval { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Interval").field("id", &self.id).finish() + impl fmt::Debug for TimeoutFuture { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("TimeoutFuture") + .field("id", &self.id) + .finish() + } } -} -impl Interval { - /// Schedule an interval to invoke `callback` every `millis` milliseconds. - /// - /// # Example - /// - /// ```no_run - /// use gloo_timers::Interval; - /// - /// let interval = Interval::new(1_000, move || { - /// // Do something... - /// }); - /// ``` - pub fn new(millis: u32, callback: F) -> Interval - where - F: 'static + FnMut(), - { - let mut callback = Some(callback); - let closure = Closure::wrap(Box::new(move || { - let mut callback = callback.take().unwrap_throw(); - callback(); - }) as Box); - - let id = window() - .set_interval_with_callback_and_timeout_and_arguments_0( - closure.as_ref().unchecked_ref::(), - millis as i32, - ) - .unwrap_throw(); - - Interval { - id: Some(id), - closure: Some(closure), + impl Future for TimeoutFuture { + type Item = (); + type Error = (); + + fn poll(&mut self) -> Poll<(), ()> { + match self.inner.poll() { + Ok(Async::Ready(_)) => Ok(Async::Ready(())), + Ok(Async::NotReady) => Ok(Async::NotReady), + // We only ever `resolve` the promise, never reject it. + Err(_) => wasm_bindgen::throw_str("unreachable"), + } } } - - /// Make this interval uncancel-able. + /// A scheduled interval as a `Stream`. /// - /// Returns the identifier returned by the original `setInterval` call, and - /// therefore you can still cancel the interval by calling `clearInterval` - /// directly (perhaps via `web_sys::clear_interval_with_handle`). + /// See `IntervalStream::new` for scheduling new intervals. /// - /// # Example - /// - /// ```no_run - /// use gloo_timers::Interval; + /// Once scheduled, if you want to stop the interval from continuing to fire, + /// you can `drop` the stream. /// - /// // We want to do stuff every second, indefinitely. - /// Interval::new(1_000, || { - /// // Do stuff... - /// }).forget(); - /// ``` - pub fn forget(mut self) -> i32 { - let id = self.id.take().unwrap_throw(); - self.closure.take().unwrap_throw().forget(); - id + /// An interval stream will never resolve to `Err`. + #[must_use = "streams do nothing unless polled or spawned"] + pub struct IntervalStream { + millis: u32, + id: Option, + closure: Closure, + inner: mpsc::UnboundedReceiver<()>, } - /// Cancel this interval so that the callback is no longer periodically - /// invoked. - /// - /// The scheduled callback is returned. - /// - /// # Example - /// - /// ```no_run - /// use gloo_timers::Interval; - /// - /// let interval = Interval::new(1_000, || { - /// // Do stuff... - /// }); - /// - /// // If we don't want this interval to run anymore, then cancel it. - /// if nevermind() { - /// interval.cancel(); - /// } - /// # fn nevermind() -> bool { true } - /// ``` - pub fn cancel(mut self) -> Closure { - self.closure.take().unwrap_throw() - } -} - -/// A scheduled interval as a `Stream`. -/// -/// See `IntervalStream::new` for scheduling new intervals. -/// -/// Once scheduled, if you want to stop the interval from continuing to fire, -/// you can `drop` the stream. -/// -/// An interval stream will never resolve to `Err`. -#[must_use = "streams do nothing unless polled or spawned"] -pub struct IntervalStream { - millis: u32, - id: Option, - closure: Closure, - inner: mpsc::UnboundedReceiver<()>, -} - -impl IntervalStream { - /// Create a new interval stream. - /// - /// Remember that streams do nothing unless polled or spawned, so either - /// spawn this stream via `wasm_bindgen_futures::spawn_local` or use it inside - /// another stream or future. - /// - /// # Example - /// - /// ```no_run - /// use futures::prelude::*; - /// use gloo_timers::IntervalStream; - /// - /// wasm_bindgen_futures::spawn_local( - /// IntervalStream::new(1_000) - /// .for_each(|_| { - /// // Do stuff every one second... - /// Ok(()) - /// }) - /// ); - /// ``` - pub fn new(millis: u32) -> IntervalStream { - let (sender, receiver) = mpsc::unbounded(); - let closure = Closure::wrap(Box::new(move || { - sender.unbounded_send(()).unwrap(); - }) as Box); - - IntervalStream { - millis, - id: None, - closure, - inner: receiver, + impl IntervalStream { + /// Create a new interval stream. + /// + /// Remember that streams do nothing unless polled or spawned, so either + /// spawn this stream via `wasm_bindgen_futures::spawn_local` or use it inside + /// another stream or future. + /// + /// # Example + /// + /// ```no_run + /// # extern crate futures_rs as futures; + /// use futures::prelude::*; + /// use gloo_timers::future::IntervalStream; + /// + /// wasm_bindgen_futures::spawn_local( + /// IntervalStream::new(1_000) + /// .for_each(|_| { + /// // Do stuff every one second... + /// Ok(()) + /// }) + /// ); + /// ``` + pub fn new(millis: u32) -> IntervalStream { + let (sender, receiver) = mpsc::unbounded(); + let closure = Closure::wrap(Box::new(move || { + sender.unbounded_send(()).unwrap(); + }) as Box); + + IntervalStream { + millis, + id: None, + closure, + inner: receiver, + } } } -} -impl Drop for IntervalStream { - fn drop(&mut self) { - if let Some(id) = self.id { - window().clear_interval_with_handle(id); + impl Drop for IntervalStream { + fn drop(&mut self) { + if let Some(id) = self.id { + window().clear_interval_with_handle(id); + } } } -} -impl fmt::Debug for IntervalStream { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("IntervalStream") - .field("id", &self.id) - .finish() + impl fmt::Debug for IntervalStream { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("IntervalStream") + .field("id", &self.id) + .finish() + } } -} -impl Stream for IntervalStream { - type Item = (); - type Error = (); - - fn poll(&mut self) -> Poll, ()> { - if self.id.is_none() { - self.id = Some( - window() - .set_interval_with_callback_and_timeout_and_arguments_0( - self.closure.as_ref().unchecked_ref::(), - self.millis as i32, - ) - .unwrap_throw(), - ); + impl Stream for IntervalStream { + type Item = (); + type Error = (); + + fn poll(&mut self) -> Poll, ()> { + if self.id.is_none() { + self.id = Some( + window() + .set_interval_with_callback_and_timeout_and_arguments_0( + self.closure.as_ref().unchecked_ref::(), + self.millis as i32, + ) + .unwrap_throw(), + ); + } + + self.inner.poll() } - - self.inner.poll() } } diff --git a/crates/timers/tests/web.rs b/crates/timers/tests/web.rs index 3d3e434e..642a948c 100644 --- a/crates/timers/tests/web.rs +++ b/crates/timers/tests/web.rs @@ -1,9 +1,11 @@ //! Test suite for the Web and headless browsers. -#![cfg(target_arch = "wasm32")] - -use futures::prelude::*; -use gloo_timers::{Interval, IntervalStream, Timeout, TimeoutFuture}; +#![cfg(all(target_arch = "wasm32", feature = "futures"))] +use futures_rs::prelude::*; +use gloo_timers::{ + callback::{Interval, Timeout}, + future::{IntervalStream, TimeoutFuture}, +}; use std::cell::Cell; use std::rc::Rc; use wasm_bindgen_test::*;