fix Thread hot reloading

This commit is contained in:
Chris Wanstrath 2025-09-21 11:21:45 -07:00
parent d8f7ed63cd
commit 66b4552def

View File

@ -7,7 +7,9 @@ import { NOSE_SYS_BIN, NOSE_USR_BIN } from "./config"
import { isFile } from "./utils" import { isFile } from "./utils"
import { AsyncLocalStorage } from "async_hooks" import { AsyncLocalStorage } from "async_hooks"
export const Thread = new AsyncLocalStorage<State>() // Ensure "Thread" lives between bun's hot reloads
const g = globalThis as typeof globalThis & { __thread?: AsyncLocalStorage<State> }
export const Thread = g.__thread ??= new AsyncLocalStorage<State>()
type State = { type State = {
id?: string id?: string