Skip to content

Commit

Permalink
Fix chia_data_layer_http service startup. Use noWait to skip waitin…
Browse files Browse the repository at this point in the history
…g for ping responses that will never arrive
  • Loading branch information
paninaro committed Sep 15, 2023
1 parent 99fed6d commit 32ba61b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/api-react/src/hooks/useService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum ServiceState {
type Options = {
keepState?: ServiceState;
disabled?: boolean;
noWait?: boolean;
};

export default function useService(
Expand All @@ -27,7 +28,7 @@ export default function useService(
error: Error | undefined;
service: ServiceNameValue;
} {
const { keepState, disabled = false } = options;
const { keepState, disabled = false, noWait = false } = options;

const [error, setError] = useState<Error | undefined>();
const [state, setState] = useState<ServiceState>(ServiceState.STOPPED);
Expand All @@ -47,6 +48,7 @@ export default function useService(

await startService({
service,
noWait,
}).unwrap();

setState(ServiceState.RUNNING);
Expand All @@ -55,7 +57,7 @@ export default function useService(
setError(e as Error);
console.error(e);
}
}, [isLoading, service, startService, disabled, state]);
}, [isLoading, service, startService, disabled, state, noWait]);

const handleStop = useCallback(async () => {
if (isLoading || disabled || state === ServiceState.STOPPED) {
Expand Down
6 changes: 6 additions & 0 deletions packages/api-react/src/hooks/useServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ function getServiceDisabled(service: ServiceNameValue, services: ServiceNameValu
return disabled || !services.includes(service);
}

function getServiceNoWait(service: ServiceNameValue, _options: Options) {
return ([ServiceName.DATALAYER_SERVER] as ServiceNameValue[]).includes(service);
}

function getServiceOptions(service: ServiceNameValue, services: ServiceNameValue[], options: Options) {
const keepState = getServiceKeepState(service, options);
const disabled = getServiceDisabled(service, services, options);
const noWait = getServiceNoWait(service, options);

return {
keepState,
disabled,
noWait,
};
}

Expand Down

0 comments on commit 32ba61b

Please sign in to comment.