Shell update

- changed shell init code to synchronous with guaranteed returns
- Shell.Instance now a normal method not a getter
This commit is contained in:
2026-09-03 11:45:19 +02:00
parent 8a349330b0
commit 2715e5e28e
2 changed files with 20 additions and 24 deletions
+15 -19
View File
@@ -10,8 +10,7 @@ import { EventEmitter } from "./event_emitter";
import { ProcessManager } from "./process_manager";
export class Shell {
static #Instance: Shell;
static #Promise: Promise<Shell> | null = null;
static #Instance: Shell | null;
private _State: Readonly<ShellState>;
private _ProcessManager: ProcessManager = new ProcessManager();
private _EventEmitter: EventEmitter<ShellEventMap> = new EventEmitter();
@@ -43,24 +42,19 @@ export class Shell {
});
}
static async init(initialState: ShellState): Promise<Shell> {
static destroy(): void {
Shell.#Instance = null;
return;
}
static init(initialState: ShellState): Shell {
if (Shell.#Instance) {
console.warn("Shell already initialized");
return this.#Instance;
return Shell.#Instance;
}
if (Shell.#Promise) return Shell.#Promise;
Shell.#Promise = (async () => {
try {
Shell.#Instance = new Shell(initialState);
return Shell.#Instance;
} finally {
Shell.#Promise = null;
}
})();
return Shell.#Promise;
Shell.#Instance = new Shell(initialState);
return Shell.#Instance;
}
public async execute(input: string): Promise<void> {
@@ -125,10 +119,12 @@ export class Shell {
return this._State;
}
public static get Instance(): Shell | undefined {
public static Instance(initialState?: ShellState): Shell {
if (!Shell.#Instance) {
console.error("Shell has not been initialised yet. Call `await Shell.init()` first.");
return;
if (!initialState) {
throw new Error("Shell needs to be initialized first");
}
Shell.#Instance = new Shell(initialState);
}
return Shell.#Instance;
}