UNPKG

999 BTypeScriptView Raw
1// Type definitions for cls-hooked 4.3
2// Project: https://github.com/jeff-lewis/cls-hooked
3// Definitions by: Leo Liang <https://github.com/aleung>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/// <reference types="node" />
7
8import { EventEmitter } from 'events';
9
10export interface Namespace {
11 active: any;
12
13 set<T>(key: string, value: T): T;
14 get(key: string): any;
15 run(fn: (...args: any[]) => void): void;
16 runAndReturn<T>(fn: (...args: any[]) => T): T;
17 runPromise<T>(fn: (...args: any[]) => Promise<T>): Promise<T>;
18 bind<F extends Function>(fn: F, context?: any): F; // tslint:disable-line: ban-types
19 bindEmitter(emitter: EventEmitter): void;
20 createContext(): any;
21 enter(context: any): void;
22 exit(context: any): void;
23}
24
25export function createNamespace(name: string): Namespace;
26export function getNamespace(name: string): Namespace | undefined;
27export function destroyNamespace(name: string): void;
28export function reset(): void;
29
\No newline at end of file