diff --git a/src/shell.ts b/src/shell.ts index 15ba3fa..8bbc8b5 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -7,7 +7,9 @@ import { NOSE_SYS_BIN, NOSE_USR_BIN } from "./config" import { isFile } from "./utils" import { AsyncLocalStorage } from "async_hooks" -export const Thread = new AsyncLocalStorage() +// Ensure "Thread" lives between bun's hot reloads +const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage } +export const Thread = g.__thread ??= new AsyncLocalStorage() type State = { id?: string