Skip to content

Commit 506a3fa

Browse files
committed
do not create resource clients until connected
1 parent 788c561 commit 506a3fa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/lib/hooks/create-resource-client.svelte.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import type { Resource, RobotClient } from '@viamrobotics/sdk';
1+
import {
2+
type Resource,
3+
type RobotClient,
4+
MachineConnectionEvent,
5+
} from '@viamrobotics/sdk';
26

3-
import { useRobotClient } from './robot-clients.svelte';
7+
import { useConnectionStatus, useRobotClient } from './robot-clients.svelte';
48

59
export type Client<T> = new (part: RobotClient, name: string) => T;
610

@@ -10,12 +14,17 @@ export const createResourceClient = <T extends Resource>(
1014
resourceName: () => string
1115
): { current: T | undefined } => {
1216
const robotClient = useRobotClient(partID);
17+
const connectionStatus = useConnectionStatus(partID);
1318

1419
const resourceClient = $derived.by<T | undefined>(() => {
1520
if (!robotClient.current) {
1621
return;
1722
}
1823

24+
if (connectionStatus.current !== MachineConnectionEvent.CONNECTED) {
25+
return;
26+
}
27+
1928
const nextClient = new client(robotClient.current, resourceName());
2029

2130
// PartIDs are used to invalidate queries for this client

0 commit comments

Comments
 (0)