make WindowListenerHandle Send + Sync so it can be remove via on_cleanup

This commit is contained in:
Greg Johnston 2024-05-24 10:19:02 -04:00
parent 694eccbadc
commit 8dd63a402b
2 changed files with 4 additions and 1 deletions

View file

@ -17,6 +17,7 @@ base64 = { version = "0.21", optional = true }
getrandom = { version = "0.2", optional = true }
js-sys = "0.3"
rand = { version = "0.8", optional = true }
send_wrapper = "0.6"
tracing = "0.1"
wasm-bindgen = "0.2"

View file

@ -4,6 +4,7 @@ use or_poisoned::OrPoisoned;
#[cfg(debug_assertions)]
use reactive_graph::diagnostics::SpecialNonReactiveZone;
use reactive_graph::owner::Owner;
use send_wrapper::SendWrapper;
use std::time::Duration;
use tachys::html::event::EventDescriptor;
#[cfg(feature = "tracing")]
@ -468,6 +469,7 @@ pub fn window_event_listener_untyped(
cb.unchecked_ref(),
);
let event_name = event_name.to_string();
let cb = SendWrapper::new(cb);
WindowListenerHandle(Box::new(move || {
_ = window().remove_event_listener_with_callback(
&event_name,
@ -511,7 +513,7 @@ where
}
/// A handle that can be called to remove a global event listener.
pub struct WindowListenerHandle(Box<dyn FnOnce()>);
pub struct WindowListenerHandle(Box<dyn FnOnce() + Send + Sync>);
impl core::fmt::Debug for WindowListenerHandle {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {