On Web, implement Send and Sync where appropriate (#2834)

This commit is contained in:
daxpedda 2023-06-05 02:44:54 +02:00 committed by GitHub
parent eb2d3894ef
commit 8f7f3efc0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 609 additions and 196 deletions

View file

@ -1,18 +1,24 @@
use super::runner;
use crate::event::Event;
use crate::event_loop::EventLoopClosed;
use crate::platform_impl::platform::r#async::Channel;
pub struct EventLoopProxy<T: 'static> {
runner: runner::Shared<T>,
runner: Channel<runner::Shared<T>, T>,
}
impl<T: 'static> EventLoopProxy<T> {
pub fn new(runner: runner::Shared<T>) -> Self {
Self { runner }
Self {
runner: Channel::new(runner, |runner, event| {
runner.send_event(Event::UserEvent(event))
})
.unwrap(),
}
}
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
self.runner.send_event(Event::UserEvent(event));
self.runner.send(event);
Ok(())
}
}