2022-11-14 19:00:20 +01:00
|
|
|
import { AsyncLocalStorage } from "async_hooks"
|
2023-01-13 20:53:46 +01:00
|
|
|
import { ContextMap } from "./mainContext"
|
2022-11-14 19:00:20 +01:00
|
|
|
|
2022-11-17 14:31:54 +01:00
|
|
|
export default class Context {
|
2023-01-13 20:53:46 +01:00
|
|
|
static storage = new AsyncLocalStorage<ContextMap>()
|
2022-11-14 19:00:20 +01:00
|
|
|
|
2023-01-13 20:53:46 +01:00
|
|
|
static run(context: ContextMap, func: any) {
|
2022-11-14 19:00:20 +01:00
|
|
|
return Context.storage.run(context, () => func())
|
|
|
|
}
|
|
|
|
|
2023-01-13 20:53:46 +01:00
|
|
|
static get(): ContextMap {
|
|
|
|
return Context.storage.getStore() as ContextMap
|
2022-11-14 19:00:20 +01:00
|
|
|
}
|
|
|
|
}
|