Skip to content

Commit

Permalink
feat(ui): avoid initial zome call timeout & excessively long default …
Browse files Browse the repository at this point in the history
…zome call timeout by calling 'ping' with very long timeout first, then using sensible default zome call timeout
  • Loading branch information
mattyg committed Oct 16, 2024
1 parent f741588 commit 18a8e4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions dnas/relay/zomes/coordinator/relay/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod contact;
pub mod message;
pub mod config;
pub mod ping;
// pub mod utils;
use hdk::prelude::*;
use relay_integrity::*;
Expand Down
6 changes: 6 additions & 0 deletions dnas/relay/zomes/coordinator/relay/src/ping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use hdk::prelude::*;

#[hdk_extern]
pub fn ping(_: ()) -> ExternResult<()> {
Ok(())
}
18 changes: 17 additions & 1 deletion ui/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { t } from '$lib/translations';
import { RelayClient } from '$store/RelayClient';
import { RelayStore } from '$store/RelayStore';
import { type RoleNameCallZomeRequest } from '@holochain/client';
import '../app.postcss';
Expand Down Expand Up @@ -45,9 +46,24 @@
}
console.log("appPort and Id is", appPort, appId)
console.log("__HC_LAUNCHER_ENV__ is", window.__HC_LAUNCHER_ENV__)
const params: AppWebsocketConnectionOptions = {url, defaultTimeout: 120000}
const params: AppWebsocketConnectionOptions = {url, defaultTimeout: 15000}
if (tokenResp) params.token = tokenResp.token
client = await AppWebsocket.connect(params)
// Call 'ping' with very long timeout
// This should be the first zome call after the client connects,
// as subsequent zome calls will be much faster and can use the default timeout.
await client.callZome(
{
role_name: "relay",
zome_name: "relay",
fn_name: "ping",
} as RoleNameCallZomeRequest,
// 240s timeout
240000
);
let profilesClient = new ProfilesClient(client, 'relay');
profilesStore = new ProfilesStore(profilesClient);
relayClient = new RelayClient(client, "relay", profilesStore);
Expand Down

0 comments on commit 18a8e4f

Please sign in to comment.