From a25b1af45690bdd8e1cbb20ee3a5b1c4342de455 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 14 Jun 2024 01:47:39 +0200 Subject: Replace `Command` with a new `Task` API with chain support --- winit/src/proxy.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'winit/src/proxy.rs') diff --git a/winit/src/proxy.rs b/winit/src/proxy.rs index 3edc30ad..0ab61375 100644 --- a/winit/src/proxy.rs +++ b/winit/src/proxy.rs @@ -4,17 +4,18 @@ use crate::futures::futures::{ task::{Context, Poll}, Future, Sink, StreamExt, }; +use crate::runtime::Action; use std::pin::Pin; /// An event loop proxy with backpressure that implements `Sink`. #[derive(Debug)] -pub struct Proxy { - raw: winit::event_loop::EventLoopProxy, - sender: mpsc::Sender, +pub struct Proxy { + raw: winit::event_loop::EventLoopProxy>, + sender: mpsc::Sender>, notifier: mpsc::Sender, } -impl Clone for Proxy { +impl Clone for Proxy { fn clone(&self) -> Self { Self { raw: self.raw.clone(), @@ -24,12 +25,12 @@ impl Clone for Proxy { } } -impl Proxy { +impl Proxy { const MAX_SIZE: usize = 100; /// Creates a new [`Proxy`] from an `EventLoopProxy`. pub fn new( - raw: winit::event_loop::EventLoopProxy, + raw: winit::event_loop::EventLoopProxy>, ) -> (Self, impl Future) { let (notifier, mut processed) = mpsc::channel(Self::MAX_SIZE); let (sender, mut receiver) = mpsc::channel(Self::MAX_SIZE); @@ -72,16 +73,16 @@ impl Proxy { ) } - /// Sends a `Message` to the event loop. + /// Sends a value to the event loop. /// /// Note: This skips the backpressure mechanism with an unbounded /// channel. Use sparingly! - pub fn send(&mut self, message: Message) + pub fn send(&mut self, value: T) where - Message: std::fmt::Debug, + T: std::fmt::Debug, { self.raw - .send_event(message) + .send_event(Action::Output(value)) .expect("Send message to event loop"); } @@ -92,7 +93,7 @@ impl Proxy { } } -impl Sink for Proxy { +impl Sink> for Proxy { type Error = mpsc::SendError; fn poll_ready( @@ -104,9 +105,9 @@ impl Sink for Proxy { fn start_send( mut self: Pin<&mut Self>, - message: Message, + action: Action, ) -> Result<(), Self::Error> { - self.sender.start_send(message) + self.sender.start_send(action) } fn poll_flush( -- cgit