fix: wait for workspace policy before creation
This commit is contained in:
@@ -9,6 +9,44 @@ export interface WorkspaceDraft {
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
let pendingPolicy: { workspaceId: string; promise: Promise<void>; resolve: () => void } | undefined;
|
||||
let failedPolicy: { workspaceId: string; error: Error } | undefined;
|
||||
|
||||
/** In-memory handoff between the footer's policy query and all session entry points. */
|
||||
export const workspacePolicyGate = {
|
||||
begin(workspaceId: string): void {
|
||||
if (pendingPolicy?.workspaceId === workspaceId) return;
|
||||
if (failedPolicy?.workspaceId === workspaceId) failedPolicy = undefined;
|
||||
let resolve!: () => void;
|
||||
const promise = new Promise<void>((onResolve) => {
|
||||
resolve = onResolve;
|
||||
});
|
||||
pendingPolicy = { workspaceId, promise, resolve };
|
||||
},
|
||||
|
||||
resolve(workspaceId: string): void {
|
||||
if (pendingPolicy?.workspaceId === workspaceId) {
|
||||
pendingPolicy.resolve();
|
||||
pendingPolicy = undefined;
|
||||
}
|
||||
if (failedPolicy?.workspaceId === workspaceId) failedPolicy = undefined;
|
||||
},
|
||||
|
||||
reject(workspaceId: string): void {
|
||||
if (pendingPolicy?.workspaceId !== workspaceId) return;
|
||||
pendingPolicy.resolve();
|
||||
pendingPolicy = undefined;
|
||||
failedPolicy = { workspaceId, error: new Error("Selected workspace policy could not be loaded.") };
|
||||
},
|
||||
|
||||
waitFor(workspaceId: string | undefined): Promise<void> {
|
||||
const failed = failedPolicy;
|
||||
if (failed && failed.workspaceId === workspaceId) return Promise.reject(failed.error);
|
||||
const pending = pendingPolicy;
|
||||
return pending && pending.workspaceId === workspaceId ? pending.promise : Promise.resolve();
|
||||
},
|
||||
};
|
||||
|
||||
const PREFIX = "thothii.workspace-registry.v1";
|
||||
const DRAFT_PREFIX = `${PREFIX}.draft.`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user