From 152679669bfba334fdb127a4b56a212050026f8b Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 17 Nov 2023 17:38:47 +0100 Subject: [PATCH] feat: buffer controller exposes its name --- src/buffer/controller.rs | 4 ++++ src/buffer/worker.rs | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/buffer/controller.rs b/src/buffer/controller.rs index 60eb94c..a2b15d0 100644 --- a/src/buffer/controller.rs +++ b/src/buffer/controller.rs @@ -28,6 +28,8 @@ use crate::api::TextChange; /// upon dropping this handle will stop the associated worker #[derive(Debug, Clone)] pub struct BufferController { + /// unique identifier of buffer + pub name: String, content: watch::Receiver, seen: Arc>, operations: mpsc::UnboundedSender, @@ -36,11 +38,13 @@ pub struct BufferController { impl BufferController { pub(crate) fn new( + name: String, content: watch::Receiver, operations: mpsc::UnboundedSender, stop: mpsc::UnboundedSender<()>, ) -> Self { BufferController { + name, content, operations, _stop: Arc::new(StopOnDrop(stop)), seen: Arc::new(RwLock::new("".into())), diff --git a/src/buffer/worker.rs b/src/buffer/worker.rs index 18e9510..a85b46f 100644 --- a/src/buffer/worker.rs +++ b/src/buffer/worker.rs @@ -24,7 +24,7 @@ pub(crate) struct BufferControllerWorker { receiver: watch::Receiver, sender: mpsc::UnboundedSender, buffer: Woot, - path: String, + name: String, stop: mpsc::UnboundedReceiver<()>, stop_control: mpsc::UnboundedSender<()>, } @@ -44,7 +44,7 @@ impl BufferControllerWorker { receiver: txt_rx, sender: op_tx, buffer: Woot::new(site_id % (2<<10), ""), // TODO remove the modulo, only for debugging! - path: path.to_string(), + name: path.to_string(), stop: end_rx, stop_control: end_tx, } @@ -53,7 +53,7 @@ impl BufferControllerWorker { async fn send_op(&self, tx: &mut BufferClient, outbound: &Op) -> crate::Result<()> { let opseq = serde_json::to_string(outbound).expect("could not serialize opseq"); let req = OperationRequest { - path: self.path.clone(), + path: self.name.clone(), hash: format!("{:x}", md5::compute(self.buffer.view())), op: Some(RawOp { opseq, user: self.uid.clone(), @@ -72,6 +72,7 @@ impl ControllerWorker for BufferControllerWorker { fn subscribe(&self) -> BufferController { BufferController::new( + self.name.clone(), self.receiver.clone(), self.sender.clone(), self.stop_control.clone(),