we no longer updata msg loop
This commit is contained in:
@@ -212,12 +212,12 @@ impl Instance {
|
|||||||
|
|
||||||
pub fn set<I: IntoMizeId, V: Into<ItemData>>(&self, id: I, value: V) -> MizeResult<()> {
|
pub fn set<I: IntoMizeId, V: Into<ItemData>>(&self, id: I, value: V) -> MizeResult<()> {
|
||||||
let id = id.to_mize_id(self)?;
|
let id = id.to_mize_id(self)?;
|
||||||
self.op_tx.send(Operation::Set(id, value.into()));
|
self.op_tx.send(Operation::Set(id, value.into(), None));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_blocking<I: IntoMizeId, V: Into<ItemData>>(&self, id: I, value: V) -> MizeResult<()> {
|
pub fn set_blocking<I: IntoMizeId, V: Into<ItemData>>(&self, id: I, value: V) -> MizeResult<()> {
|
||||||
handle_operation(&mut Operation::Set(id.to_mize_id(self)?, value.into()), self)?;
|
handle_operation(&mut Operation::Set(id.to_mize_id(self)?, value.into(), None), self)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use super::subscription::{Subscription, Update};
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Operation {
|
pub enum Operation {
|
||||||
Set(MizeId, ItemData),
|
Set(MizeId, ItemData, Option<Connection>), // bool: is_from_update_msg
|
||||||
Msg(MizeMessage),
|
Msg(MizeMessage),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ pub fn updater_thread(operation_rx : Receiver<Operation>, instance: &Instance) -
|
|||||||
loop {
|
loop {
|
||||||
let mut operation = operation_rx.recv()?;
|
let mut operation = operation_rx.recv()?;
|
||||||
let op_str = match operation {
|
let op_str = match operation {
|
||||||
Operation::Set(_, _) => "SET",
|
Operation::Set(_, _, _) => "SET",
|
||||||
Operation::Msg(_) => "MSG",
|
Operation::Msg(_) => "MSG",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ pub fn updater_thread(operation_rx : Receiver<Operation>, instance: &Instance) -
|
|||||||
|
|
||||||
pub fn handle_operation(operation: &mut Operation, instance: &Instance) -> MizeResult<()> {
|
pub fn handle_operation(operation: &mut Operation, instance: &Instance) -> MizeResult<()> {
|
||||||
match operation {
|
match operation {
|
||||||
Operation::Set(id, value) => {
|
Operation::Set(id, value, maybe_conn) => {
|
||||||
let item_data: ItemData = value.to_owned();
|
let item_data: ItemData = value.to_owned();
|
||||||
let mut item = instance.get(id.clone())?;
|
let mut item = instance.get(id.clone())?;
|
||||||
item.merge(item_data)?;
|
item.merge(item_data)?;
|
||||||
@@ -65,6 +65,17 @@ pub fn handle_operation(operation: &mut Operation, instance: &Instance) -> MizeR
|
|||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
};
|
};
|
||||||
for sub in vec.iter_mut() {
|
for sub in vec.iter_mut() {
|
||||||
|
|
||||||
|
// don't handle sub of type connection, in case the update comes from this
|
||||||
|
// connection
|
||||||
|
if let Some(conn) = maybe_conn {
|
||||||
|
if let Subscription::Connection(conn2) = sub {
|
||||||
|
if conn.id == conn2.id {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub.handle(update.clone());
|
sub.handle(update.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,7 +117,8 @@ fn handle_msg(msg: &mut MizeMessage, instance: &Instance) -> MizeResult<()> {
|
|||||||
MessageCmd::Update => {
|
MessageCmd::Update => {
|
||||||
let data = msg.data()?;
|
let data = msg.data()?;
|
||||||
let id = msg.id(instance)?;
|
let id = msg.id(instance)?;
|
||||||
instance.set(id.clone(), data);
|
let connection = instance.get_connection(msg.conn_id)?;
|
||||||
|
instance.op_tx.send(Operation::Set(id.clone(), data, Some(connection)));
|
||||||
},
|
},
|
||||||
|
|
||||||
// this should check, if the update is valid
|
// this should check, if the update is valid
|
||||||
@@ -114,7 +126,8 @@ fn handle_msg(msg: &mut MizeMessage, instance: &Instance) -> MizeResult<()> {
|
|||||||
MessageCmd::UpdateRequest => {
|
MessageCmd::UpdateRequest => {
|
||||||
let data = msg.data()?;
|
let data = msg.data()?;
|
||||||
let id = msg.id(instance)?;
|
let id = msg.id(instance)?;
|
||||||
instance.set(id.clone(), data);
|
let connection = instance.get_connection(msg.conn_id)?;
|
||||||
|
instance.op_tx.send(Operation::Set(id.clone(), data, Some(connection)));
|
||||||
},
|
},
|
||||||
|
|
||||||
MessageCmd::Give => {
|
MessageCmd::Give => {
|
||||||
|
|||||||
Reference in New Issue
Block a user