chore: packed clonable handles in sub struct

This commit is contained in:
əlemi 2023-11-27 14:55:46 +01:00
parent 15ad6dba55
commit 1265f716d6

View file

@ -19,17 +19,21 @@ use super::controller::BufferController;
pub(crate) struct BufferControllerWorker { pub(crate) struct BufferControllerWorker {
uid: String, uid: String,
name: String,
buffer: Woot,
content: watch::Sender<String>, content: watch::Sender<String>,
operations: mpsc::UnboundedReceiver<TextChange>, operations: mpsc::UnboundedReceiver<TextChange>,
receiver: watch::Receiver<String>, poller: mpsc::Receiver<oneshot::Sender<()>>,
sender: mpsc::UnboundedSender<TextChange>,
buffer: Woot,
name: String,
stop: mpsc::UnboundedReceiver<()>,
stop_control: mpsc::UnboundedSender<()>,
poller_rx: mpsc::Receiver<oneshot::Sender<()>>,
poller_tx: mpsc::Sender<oneshot::Sender<()>>,
pollers: Vec<oneshot::Sender<()>>, pollers: Vec<oneshot::Sender<()>>,
handles: ClonableHandlesForController,
stop: mpsc::UnboundedReceiver<()>,
}
struct ClonableHandlesForController {
operations: mpsc::UnboundedSender<TextChange>,
poller: mpsc::Sender<oneshot::Sender<()>>,
stop: mpsc::UnboundedSender<()>,
content: watch::Receiver<String>,
} }
impl BufferControllerWorker { impl BufferControllerWorker {
@ -42,16 +46,20 @@ impl BufferControllerWorker {
uid.hash(&mut hasher); uid.hash(&mut hasher);
let site_id = hasher.finish() as usize; let site_id = hasher.finish() as usize;
BufferControllerWorker { BufferControllerWorker {
uid, poller_rx, poller_tx, uid,
pollers: Vec::new(), name: path.to_string(),
buffer: Woot::new(site_id % (2<<10), ""), // TODO remove the modulo, only for debugging!
content: txt_tx, content: txt_tx,
operations: op_rx, operations: op_rx,
receiver: txt_rx, poller: poller_rx,
sender: op_tx, pollers: Vec::new(),
buffer: Woot::new(site_id % (2<<10), ""), // TODO remove the modulo, only for debugging! handles: ClonableHandlesForController {
name: path.to_string(), operations: op_tx,
poller: poller_tx,
stop: end_tx,
content: txt_rx,
},
stop: end_rx, stop: end_rx,
stop_control: end_tx,
} }
} }
@ -78,10 +86,10 @@ impl ControllerWorker<TextChange> for BufferControllerWorker {
fn subscribe(&self) -> BufferController { fn subscribe(&self) -> BufferController {
BufferController::new( BufferController::new(
self.name.clone(), self.name.clone(),
self.receiver.clone(), self.handles.content.clone(),
self.sender.clone(), self.handles.operations.clone(),
self.poller_tx.clone(), self.handles.poller.clone(),
self.stop_control.clone(), self.handles.stop.clone(),
) )
} }
@ -95,7 +103,7 @@ impl ControllerWorker<TextChange> for BufferControllerWorker {
_ = self.stop.recv() => break, _ = self.stop.recv() => break,
// received a new poller, add it to collection // received a new poller, add it to collection
res = self.poller_rx.recv() => match res { res = self.poller.recv() => match res {
None => break tracing::error!("poller channel closed"), None => break tracing::error!("poller channel closed"),
Some(tx) => self.pollers.push(tx), Some(tx) => self.pollers.push(tx),
}, },