push updated state to clients over SSE (ISS-129)
CI / build + unit + e2e (pull_request) Successful in 11m7s
CI / build + unit + e2e (pull_request) Successful in 11m7s
This commit is contained in:
+6
-4
@@ -211,12 +211,14 @@ export async function persist(instance: GameDb): Promise<void> {
|
||||
await fs.rename(tmp, instance.file);
|
||||
}
|
||||
|
||||
// Singleton for the app process; openGameDb() is the uncached variant (tests).
|
||||
let ready: Promise<GameDb> | null = null;
|
||||
// Singleton for the app process; openGameDb() is the uncached variant (tests). ISS-129 (v0.57.0):
|
||||
// lives on globalThis because Next.js can load this module more than once per process —
|
||||
// instrumentation.ts and route handlers get separate module instances, so a plain `let` would give
|
||||
// each its own in-memory sql.js DB (both persisting to the same file). One world per process.
|
||||
const g = globalThis as unknown as { __flightGameDb?: Promise<GameDb> };
|
||||
|
||||
export function getGameDb(): Promise<GameDb> {
|
||||
if (!ready) ready = open(defaultDbPath());
|
||||
return ready;
|
||||
return (g.__flightGameDb ??= open(defaultDbPath()));
|
||||
}
|
||||
|
||||
export async function openGameDb(file: string): Promise<GameDb> {
|
||||
|
||||
Reference in New Issue
Block a user