mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
feat: buffer controller exposes its name
This commit is contained in:
parent
8dc3538f32
commit
152679669b
2 changed files with 8 additions and 3 deletions
|
@ -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<String>,
|
||||
seen: Arc<RwLock<String>>,
|
||||
operations: mpsc::UnboundedSender<TextChange>,
|
||||
|
@ -36,11 +38,13 @@ pub struct BufferController {
|
|||
|
||||
impl BufferController {
|
||||
pub(crate) fn new(
|
||||
name: String,
|
||||
content: watch::Receiver<String>,
|
||||
operations: mpsc::UnboundedSender<TextChange>,
|
||||
stop: mpsc::UnboundedSender<()>,
|
||||
) -> Self {
|
||||
BufferController {
|
||||
name,
|
||||
content, operations,
|
||||
_stop: Arc::new(StopOnDrop(stop)),
|
||||
seen: Arc::new(RwLock::new("".into())),
|
||||
|
|
|
@ -24,7 +24,7 @@ pub(crate) struct BufferControllerWorker {
|
|||
receiver: watch::Receiver<String>,
|
||||
sender: mpsc::UnboundedSender<TextChange>,
|
||||
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<Channel>, 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<TextChange> for BufferControllerWorker {
|
|||
|
||||
fn subscribe(&self) -> BufferController {
|
||||
BufferController::new(
|
||||
self.name.clone(),
|
||||
self.receiver.clone(),
|
||||
self.sender.clone(),
|
||||
self.stop_control.clone(),
|
||||
|
|
Loading…
Reference in a new issue