nose-pluto/app/src/state.ts
Chris Wanstrath 1c3dd16517 reeeeeboooot
2025-09-22 14:55:32 -07:00

15 lines
405 B
TypeScript

import { AsyncLocalStorage } from "async_hooks"
export type State = {
id?: string
session?: string
project?: string
}
// Ensure "ALS" lives between bun's hot reloads
const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage<State> }
export const ALS = g.__thread ??= new AsyncLocalStorage<State>()
export function getState(): State | undefined {
return ALS.getStore()
}