nose-pluto/src/state.ts
Chris Wanstrath 8f7fc5d36b getState
2025-09-21 12:37:21 -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()
}