diff --git a/src/api/controller.rs b/src/api/controller.rs index 15dbdb7..0a8b990 100644 --- a/src/api/controller.rs +++ b/src/api/controller.rs @@ -45,7 +45,7 @@ pub trait Controller : Sized + Send + Sync { } } - fn callback(&self, cb: ControllerCallback); + fn callback(&self, cb: ControllerCallback); fn clear_callback(&self); @@ -71,22 +71,22 @@ pub trait Controller : Sized + Send + Sync { /// type wrapper for Boxed dyn callback -pub struct ControllerCallback(Box); +pub struct ControllerCallback(Box); -impl ControllerCallback { - pub fn call(&self) { - self.0() // lmao at this syntax +impl ControllerCallback { + pub fn call(&self, x: T) { + self.0(x) // lmao at this syntax } } -impl std::fmt::Debug for ControllerCallback { +impl std::fmt::Debug for ControllerCallback { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "ControllerCallback {{ {:p} }}", self.0) } } -impl From for ControllerCallback { - fn from(value: T) -> Self { +impl From for ControllerCallback { + fn from(value: X) -> Self { Self(Box::new(value)) } } diff --git a/src/buffer/controller.rs b/src/buffer/controller.rs index 7f4977d..2766056 100644 --- a/src/buffer/controller.rs +++ b/src/buffer/controller.rs @@ -53,7 +53,7 @@ pub(crate) struct BufferControllerInner { pub(crate) stopper: mpsc::UnboundedSender<()>, // just exist pub(crate) content_request: mpsc::Sender>, pub(crate) delta_request: mpsc::Sender<(LocalVersion, oneshot::Sender<(LocalVersion, TextChange)>)>, - pub(crate) callback: watch::Sender>, + pub(crate) callback: watch::Sender>>, } #[async_trait] @@ -98,7 +98,7 @@ impl Controller for BufferController { Ok(()) } - fn callback(&self, cb: ControllerCallback) { + fn callback(&self, cb: ControllerCallback) { if self.0.callback.send(Some(cb)).is_err() { // TODO should we panic? we failed what we were supposed to do tracing::error!("no active buffer worker to run registered callback!"); diff --git a/src/buffer/worker.rs b/src/buffer/worker.rs index 3d416ed..140d930 100644 --- a/src/buffer/worker.rs +++ b/src/buffer/worker.rs @@ -24,7 +24,7 @@ pub(crate) struct BufferWorker { delta_req: mpsc::Receiver<(LocalVersion, oneshot::Sender<(LocalVersion, TextChange)>)>, stop: mpsc::UnboundedReceiver<()>, controller: BufferController, - callback: watch::Receiver>, + callback: watch::Receiver>>, } impl BufferWorker { @@ -135,7 +135,7 @@ impl ControllerWorker for BufferWorker { tx.send(()).unwrap_or_warn("could not wake up poller"); } if let Some(cb) = self.callback.borrow().as_ref() { - cb.call(); // TODO should we run this on another task/thread? + cb.call(self.controller.clone()); // TODO should we run this on another task/thread? } }, Err(e) => tracing::error!("could not deserialize operation from server: {}", e), diff --git a/src/cursor/controller.rs b/src/cursor/controller.rs index 0e46055..fe862e4 100644 --- a/src/cursor/controller.rs +++ b/src/cursor/controller.rs @@ -29,7 +29,7 @@ pub(crate) struct CursorControllerInner { pub(crate) op: mpsc::Sender, pub(crate) last_op: Mutex>, pub(crate) stream: Mutex>, - pub(crate) callback: watch::Sender>, + pub(crate) callback: watch::Sender>>, pub(crate) stop: mpsc::UnboundedSender<()>, } @@ -63,7 +63,7 @@ impl Controller for CursorController { Ok(self.0.last_op.lock().await.changed().await?) } - fn callback(&self, cb: ControllerCallback) { + fn callback(&self, cb: ControllerCallback) { if self.0.callback.send(Some(cb)).is_err() { // TODO should we panic? we failed what we were supposed to do tracing::error!("no active cursor worker to run registered callback!"); diff --git a/src/cursor/worker.rs b/src/cursor/worker.rs index 1d92beb..10766bd 100644 --- a/src/cursor/worker.rs +++ b/src/cursor/worker.rs @@ -14,7 +14,7 @@ pub(crate) struct CursorWorker { channel: broadcast::Sender, stop: mpsc::UnboundedReceiver<()>, controller: CursorController, - callback: watch::Receiver>, + callback: watch::Receiver>>, } impl Default for CursorWorker { @@ -62,7 +62,7 @@ impl ControllerWorker for CursorWorker { self.channel.send(cur.clone()).unwrap_or_warn("could not broadcast event"); self.changed.send(cur).unwrap_or_warn("could not update last event"); if let Some(cb) = self.callback.borrow().as_ref() { - cb.call(); // TODO should this run in its own task/thread? + cb.call(self.controller.clone()); // TODO should this run in its own task/thread? } }, else => break,