feat: buffer controller exposes its name

This commit is contained in:
əlemi 2023-11-17 17:38:47 +01:00
parent 8dc3538f32
commit 152679669b
2 changed files with 8 additions and 3 deletions

View file

@ -28,6 +28,8 @@ use crate::api::TextChange;
/// upon dropping this handle will stop the associated worker /// upon dropping this handle will stop the associated worker
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BufferController { pub struct BufferController {
/// unique identifier of buffer
pub name: String,
content: watch::Receiver<String>, content: watch::Receiver<String>,
seen: Arc<RwLock<String>>, seen: Arc<RwLock<String>>,
operations: mpsc::UnboundedSender<TextChange>, operations: mpsc::UnboundedSender<TextChange>,
@ -36,11 +38,13 @@ pub struct BufferController {
impl BufferController { impl BufferController {
pub(crate) fn new( pub(crate) fn new(
name: String,
content: watch::Receiver<String>, content: watch::Receiver<String>,
operations: mpsc::UnboundedSender<TextChange>, operations: mpsc::UnboundedSender<TextChange>,
stop: mpsc::UnboundedSender<()>, stop: mpsc::UnboundedSender<()>,
) -> Self { ) -> Self {
BufferController { BufferController {
name,
content, operations, content, operations,
_stop: Arc::new(StopOnDrop(stop)), _stop: Arc::new(StopOnDrop(stop)),
seen: Arc::new(RwLock::new("".into())), seen: Arc::new(RwLock::new("".into())),

View file

@ -24,7 +24,7 @@ pub(crate) struct BufferControllerWorker {
receiver: watch::Receiver<String>, receiver: watch::Receiver<String>,
sender: mpsc::UnboundedSender<TextChange>, sender: mpsc::UnboundedSender<TextChange>,
buffer: Woot, buffer: Woot,
path: String, name: String,
stop: mpsc::UnboundedReceiver<()>, stop: mpsc::UnboundedReceiver<()>,
stop_control: mpsc::UnboundedSender<()>, stop_control: mpsc::UnboundedSender<()>,
} }
@ -44,7 +44,7 @@ impl BufferControllerWorker {
receiver: txt_rx, receiver: txt_rx,
sender: op_tx, sender: op_tx,
buffer: Woot::new(site_id % (2<<10), ""), // TODO remove the modulo, only for debugging! 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: end_rx,
stop_control: end_tx, stop_control: end_tx,
} }
@ -53,7 +53,7 @@ impl BufferControllerWorker {
async fn send_op(&self, tx: &mut BufferClient<Channel>, outbound: &Op) -> crate::Result<()> { async fn send_op(&self, tx: &mut BufferClient<Channel>, outbound: &Op) -> crate::Result<()> {
let opseq = serde_json::to_string(outbound).expect("could not serialize opseq"); let opseq = serde_json::to_string(outbound).expect("could not serialize opseq");
let req = OperationRequest { let req = OperationRequest {
path: self.path.clone(), path: self.name.clone(),
hash: format!("{:x}", md5::compute(self.buffer.view())), hash: format!("{:x}", md5::compute(self.buffer.view())),
op: Some(RawOp { op: Some(RawOp {
opseq, user: self.uid.clone(), opseq, user: self.uid.clone(),
@ -72,6 +72,7 @@ impl ControllerWorker<TextChange> for BufferControllerWorker {
fn subscribe(&self) -> BufferController { fn subscribe(&self) -> BufferController {
BufferController::new( BufferController::new(
self.name.clone(),
self.receiver.clone(), self.receiver.clone(),
self.sender.clone(), self.sender.clone(),
self.stop_control.clone(), self.stop_control.clone(),