Skip to content

Commit 05160f0

Browse files
committed
project hub api -- add function to wait until ready
1 parent f42a47f commit 05160f0

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/packages/conat/project/api/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export interface ProjectApi {
1010
editor: Editor;
1111
jupyter: Jupyter;
1212
sync: Sync;
13-
isRunning: () => Promise<boolean>;
13+
isReady: () => Promise<boolean>;
14+
waitUntilReady: () => Promise<void>;
1415
}
1516

1617
const ProjectApiStructure = {
@@ -20,7 +21,11 @@ const ProjectApiStructure = {
2021
sync,
2122
} as const;
2223

23-
export function initProjectApi(callProjectApi, isRunning): ProjectApi {
24+
export function initProjectApi({
25+
callProjectApi,
26+
isReady,
27+
waitUntilReady,
28+
}): ProjectApi {
2429
const projectApi: any = {};
2530
for (const group in ProjectApiStructure) {
2631
if (projectApi[group] == null) {
@@ -36,6 +41,7 @@ export function initProjectApi(callProjectApi, isRunning): ProjectApi {
3641
);
3742
}
3843
}
39-
projectApi.isRunning = isRunning;
44+
projectApi.isReady = isReady;
45+
projectApi.waitUntilReady = waitUntilReady;
4046
return projectApi as ProjectApi;
4147
}

src/packages/conat/project/api/project-client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ export function projectApiClient({
2626
}
2727
const subject = projectSubject({ project_id, compute_server_id, service });
2828

29-
const isRunning = async () => {
29+
const isReady = async () => {
3030
return await client.interest(subject);
3131
};
3232

33+
const waitUntilReady = async ({ timeout }: { timeout?: number } = {}) => {
34+
await client.waitForInterest(subject, { timeout });
35+
};
36+
3337
const callProjectApi = async ({ name, args }) => {
3438
return await callProject({
3539
client,
@@ -39,7 +43,7 @@ export function projectApiClient({
3943
args,
4044
});
4145
};
42-
return initProjectApi(callProjectApi, isRunning);
46+
return initProjectApi({ callProjectApi, isReady, waitUntilReady });
4347
}
4448

4549
async function callProject({

0 commit comments

Comments
 (0)