1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export type Context = {
|
10 | [key: string]: any
|
11 | };
|
12 |
|
13 | export type BindCallbackFn<T> = (...args: any[]) => T;
|
14 | export type RunCallbackFn<T> = (context: Context) => T;
|
15 |
|
16 | export interface Namespace {
|
17 | readonly name: string;
|
18 |
|
19 | readonly active: Context;
|
20 | createContext(): Context;
|
21 |
|
22 | set<T>(key: string, value: T): T;
|
23 | get<T>(key: string): T | undefined;
|
24 |
|
25 | run<T = void>(callback: RunCallbackFn<T>): Context;
|
26 | runAndReturn<T>(callback: RunCallbackFn<T>): T;
|
27 |
|
28 | bind<T = void>(callback: BindCallbackFn<T>, context?: Context): BindCallbackFn<T>;
|
29 | bindEmitter(emitter: NodeJS.EventEmitter): void;
|
30 |
|
31 | enter(context: Context): void;
|
32 | exit(context: Context): void;
|
33 | }
|
34 |
|
35 | export function createNamespace(name: string): Namespace;
|
36 | export function getNamespace(name: string): Namespace | undefined;
|
37 | export function destroyNamespace(name: string): void;
|
38 | export function reset(): void;
|
39 |
|
40 |
|
41 |
|
42 |
|