-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup-status.ts
More file actions
51 lines (43 loc) · 1.24 KB
/
setup-status.ts
File metadata and controls
51 lines (43 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { Disposable, LogOutputChannel } from "vscode";
import { createEmitter } from "./emitter.ts";
import { checkIsSetupRequired } from "./setup.ts";
export type SetupStatus = "ok" | "setup_required";
export interface SetupStatusTracker extends Disposable {
status(): SetupStatus;
onChange(callback: (status: SetupStatus) => void): void;
}
/**
* Checks the status of the LocalStack installation.
*/
export async function createSetupStatusTracker(
outputChannel: LogOutputChannel,
): Promise<SetupStatusTracker> {
let status: SetupStatus | undefined;
const emitter = createEmitter<SetupStatus>(outputChannel);
let timeout: NodeJS.Timeout | undefined;
const startChecking = async () => {
const setupRequired = await checkIsSetupRequired(outputChannel);
const newStatus = setupRequired ? "setup_required" : "ok";
if (status !== newStatus) {
status = newStatus;
await emitter.emit(status);
}
timeout = setTimeout(() => void startChecking(), 1_000);
};
await startChecking();
return {
status() {
// biome-ignore lint/style/noNonNullAssertion: false positive
return status!;
},
onChange(callback) {
emitter.on(callback);
if (status) {
callback(status);
}
},
dispose() {
clearTimeout(timeout);
},
};
}