Serialize initial follow state in leader and reflect it in follower
This commit is contained in:
parent
0fdaa1d715
commit
f0b7bd6e17
10 changed files with 246 additions and 63 deletions
|
@ -494,14 +494,13 @@ impl Client {
|
|||
message_type_id,
|
||||
Arc::new(move |handle, envelope, cx| {
|
||||
if let Some(client) = client.upgrade() {
|
||||
let model = handle.downcast::<E>().unwrap();
|
||||
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
|
||||
let handle = if let AnyEntityHandle::Model(handle) = handle {
|
||||
handle
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
let model = handle.downcast::<E>().unwrap();
|
||||
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
|
||||
handler(model, *envelope, client.clone(), cx).boxed_local()
|
||||
} else {
|
||||
async move { Ok(()) }.boxed_local()
|
||||
|
@ -513,7 +512,7 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_entity_request_handler<M, E, H, F>(self: &Arc<Self>, handler: H)
|
||||
pub fn add_model_request_handler<M, E, H, F>(self: &Arc<Self>, handler: H)
|
||||
where
|
||||
M: EntityMessage + RequestMessage,
|
||||
E: Entity,
|
||||
|
@ -546,6 +545,39 @@ impl Client {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn add_view_request_handler<M, E, H, F>(self: &Arc<Self>, handler: H)
|
||||
where
|
||||
M: EntityMessage + RequestMessage,
|
||||
E: View,
|
||||
H: 'static
|
||||
+ Send
|
||||
+ Sync
|
||||
+ Fn(ViewHandle<E>, TypedEnvelope<M>, Arc<Self>, AsyncAppContext) -> F,
|
||||
F: 'static + Future<Output = Result<M::Response>>,
|
||||
{
|
||||
self.add_view_message_handler(move |view, envelope, client, cx| {
|
||||
let receipt = envelope.receipt();
|
||||
let response = handler(view, envelope, client.clone(), cx);
|
||||
async move {
|
||||
match response.await {
|
||||
Ok(response) => {
|
||||
client.respond(receipt, response)?;
|
||||
Ok(())
|
||||
}
|
||||
Err(error) => {
|
||||
client.respond_with_error(
|
||||
receipt,
|
||||
proto::Error {
|
||||
message: error.to_string(),
|
||||
},
|
||||
)?;
|
||||
Err(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn has_keychain_credentials(&self, cx: &AsyncAppContext) -> bool {
|
||||
read_credentials_from_keychain(cx).is_some()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue