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