Files
stats/packages/db/src/session-context.ts
Carl-Gerhard Lindesvärd f454449365 fix: read-after-write issues (#215)
* fix: read-after-write issues

* fix: coderabbit comments

* fix: clear cache on invite

* fix: use primary after a read
2025-10-31 09:56:07 +01:00

13 lines
362 B
TypeScript

import { AsyncLocalStorage } from 'node:async_hooks';
type Ctx = { sessionId: string | null };
export const als = new AsyncLocalStorage<Ctx>();
export const runWithAlsSession = <T>(
sid: string | null | undefined,
fn: () => Promise<T>,
) => als.run({ sessionId: sid || null }, fn);
export const getAlsSessionId = () => als.getStore()?.sessionId ?? null;