🎨
This commit is contained in:
parent
03812a6cdc
commit
6a6cd68df4
1 changed files with 14 additions and 12 deletions
|
@ -514,39 +514,41 @@ impl Client {
|
||||||
if let Some(handler) = state.model_handlers.get_mut(&handler_key) {
|
if let Some(handler) = state.model_handlers.get_mut(&handler_key) {
|
||||||
let mut handler = handler.take().unwrap();
|
let mut handler = handler.take().unwrap();
|
||||||
drop(state); // Avoid deadlocks if the handler interacts with rpc::Client
|
drop(state); // Avoid deadlocks if the handler interacts with rpc::Client
|
||||||
|
let future = (handler)(message, &cx);
|
||||||
|
{
|
||||||
|
let mut state = this.state.write();
|
||||||
|
if state.model_handlers.contains_key(&handler_key) {
|
||||||
|
state.model_handlers.insert(handler_key, Some(handler));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let client_id = this.id;
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"rpc message received. client_id:{}, name:{}",
|
"rpc message received. client_id:{}, name:{}",
|
||||||
this.id,
|
client_id,
|
||||||
type_name
|
type_name
|
||||||
);
|
);
|
||||||
|
|
||||||
let future = (handler)(message, &cx);
|
|
||||||
let client_id = this.id;
|
|
||||||
cx.foreground()
|
cx.foreground()
|
||||||
.spawn(async move {
|
.spawn(async move {
|
||||||
match future.await {
|
match future.await {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"rpc message handled. client_id:{}, name:{}",
|
"{}: rpc message '{}' handled",
|
||||||
client_id,
|
client_id,
|
||||||
type_name
|
type_name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
log::error!(
|
log::error!(
|
||||||
"error handling rpc message. client_id:{}, name:{}, error: {}",
|
"{}: error handling rpc message '{}', {}",
|
||||||
client_id, type_name, error
|
client_id,
|
||||||
|
type_name,
|
||||||
|
error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
let mut state = this.state.write();
|
|
||||||
if state.model_handlers.contains_key(&handler_key) {
|
|
||||||
state.model_handlers.insert(handler_key, Some(handler));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log::info!("unhandled message {}", type_name);
|
log::info!("unhandled message {}", type_name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue