* fix: read-after-write issues * fix: coderabbit comments * fix: clear cache on invite * fix: use primary after a read
13 lines
362 B
TypeScript
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;
|