|
@@ -7,6 +7,7 @@
|
|
|
//! Because RIC doesn't work on Safari, we polyfill using the "ricpolyfill.js" file and use some basic detection to see
|
|
|
//! if RIC is available.
|
|
|
|
|
|
+use futures_util::StreamExt;
|
|
|
use gloo_timers::future::TimeoutFuture;
|
|
|
use js_sys::Function;
|
|
|
use wasm_bindgen::{prelude::Closure, JsCast, JsValue};
|
|
@@ -14,21 +15,21 @@ use web_sys::{window, Window};
|
|
|
|
|
|
pub(crate) struct RafLoop {
|
|
|
window: Window,
|
|
|
- ric_receiver: async_channel::Receiver<u32>,
|
|
|
- raf_receiver: async_channel::Receiver<()>,
|
|
|
+ ric_receiver: futures_channel::mpsc::UnboundedReceiver<u32>,
|
|
|
+ raf_receiver: futures_channel::mpsc::UnboundedReceiver<()>,
|
|
|
ric_closure: Closure<dyn Fn(JsValue)>,
|
|
|
raf_closure: Closure<dyn Fn(JsValue)>,
|
|
|
}
|
|
|
|
|
|
impl RafLoop {
|
|
|
pub fn new() -> Self {
|
|
|
- let (raf_sender, raf_receiver) = async_channel::unbounded();
|
|
|
+ let (raf_sender, raf_receiver) = futures_channel::mpsc::unbounded();
|
|
|
|
|
|
let raf_closure: Closure<dyn Fn(JsValue)> = Closure::wrap(Box::new(move |_v: JsValue| {
|
|
|
- raf_sender.try_send(()).unwrap()
|
|
|
+ raf_sender.unbounded_send(()).unwrap()
|
|
|
}));
|
|
|
|
|
|
- let (ric_sender, ric_receiver) = async_channel::unbounded();
|
|
|
+ let (ric_sender, ric_receiver) = futures_channel::mpsc::unbounded();
|
|
|
|
|
|
let has_idle_callback = {
|
|
|
let bo = window().unwrap().dyn_into::<js_sys::Object>().unwrap();
|
|
@@ -45,7 +46,7 @@ impl RafLoop {
|
|
|
10
|
|
|
};
|
|
|
|
|
|
- ric_sender.try_send(time_remaining).unwrap()
|
|
|
+ ric_sender.unbounded_send(time_remaining).unwrap()
|
|
|
}));
|
|
|
|
|
|
// execute the polyfill for safari
|
|
@@ -64,16 +65,16 @@ impl RafLoop {
|
|
|
}
|
|
|
}
|
|
|
/// waits for some idle time and returns a timeout future that expires after the idle time has passed
|
|
|
- pub async fn wait_for_idle_time(&self) -> TimeoutFuture {
|
|
|
+ pub async fn wait_for_idle_time(&mut self) -> TimeoutFuture {
|
|
|
let ric_fn = self.ric_closure.as_ref().dyn_ref::<Function>().unwrap();
|
|
|
let _cb_id: u32 = self.window.request_idle_callback(ric_fn).unwrap();
|
|
|
- let deadline = self.ric_receiver.recv().await.unwrap();
|
|
|
+ let deadline = self.ric_receiver.next().await.unwrap();
|
|
|
TimeoutFuture::new(deadline)
|
|
|
}
|
|
|
|
|
|
- pub async fn wait_for_raf(&self) {
|
|
|
+ pub async fn wait_for_raf(&mut self) {
|
|
|
let raf_fn = self.raf_closure.as_ref().dyn_ref::<Function>().unwrap();
|
|
|
let _id: i32 = self.window.request_animation_frame(raf_fn).unwrap();
|
|
|
- self.raf_receiver.recv().await.unwrap();
|
|
|
+ self.raf_receiver.next().await.unwrap();
|
|
|
}
|
|
|
}
|