Skip to content

Commit

Permalink
simplify via 'let else'
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Sep 2, 2024
1 parent b9eef7e commit f286331
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions capnp-rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1481,35 +1481,31 @@ impl<VatId> ConnectionState<VatId> {

if is_promise {
// We need to construct a PromiseClient around this import, if we haven't already.
match state.imports.borrow_mut().slots.get_mut(&import_id) {
Some(import) => {
match &import.app_client {
Some(c) => {
// Use the existing one.
Box::new(c.upgrade().expect("dangling client ref?"))
}
None => {
// Create a promise for this import's resolution.
let mut tmp = state.imports.borrow_mut();
let Some(import) = tmp.slots.get_mut(&import_id) else {
unreachable!()
};
match &import.app_client {
Some(c) => {
// Use the existing one.
Box::new(c.upgrade().expect("dangling client ref?"))
}
None => {
// Create a promise for this import's resolution.

let client: Box<Client<VatId>> = Box::new(import_client.into());
let client: Box<dyn ClientHook> = client;
let client: Box<Client<VatId>> = Box::new(import_client.into());
let client: Box<dyn ClientHook> = client;

// XXX do I need something like this?
// Make sure the import is not destroyed while this promise exists.
// let promise = promise.attach(client.add_ref());
// XXX do I need something like this?
// Make sure the import is not destroyed while this promise exists.
// let promise = promise.attach(client.add_ref());

let client =
PromiseClient::new(&connection_state, client, Some(import_id));
let client = PromiseClient::new(&connection_state, client, Some(import_id));

import.promise_client_to_resolve = Some(Rc::downgrade(&client));
let client: Box<Client<VatId>> = Box::new(client.into());
import.app_client = Some(client.downgrade());
client
}
}
}
None => {
unreachable!()
import.promise_client_to_resolve = Some(Rc::downgrade(&client));
let client: Box<Client<VatId>> = Box::new(client.into());
import.app_client = Some(client.downgrade());
client
}
}
} else {
Expand Down

0 comments on commit f286331

Please sign in to comment.