@midwayjs/async-hooks-context-manager
Version:
midway async hooks context manager
49 lines • 1.81 kB
TypeScript
import { AsyncContext, AsyncContextManager } from '@midwayjs/core';
export declare class AsyncHooksContextManager implements AsyncContextManager {
private _asyncHook;
private _contexts;
private _stack;
constructor();
active(): AsyncContext;
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: AsyncContext, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
enable(): this;
disable(): this;
/**
* Init hook will be called when userland create a async context, setting the
* context as the current one if it exist.
* @param uid id of the async context
* @param type the resource type
*/
private _init;
/**
* Destroy hook will be called when a given context is no longer used so we can
* remove its attached context.
* @param uid uid of the async context
*/
private _destroy;
/**
* Before hook is called just before executing a async context.
* @param uid uid of the async context
*/
private _before;
/**
* After hook is called just after completing the execution of a async context.
*/
private _after;
/**
* Set the given context as active
*/
private _enterContext;
/**
* Remove the context at the root of the stack
*/
private _exitContext;
/**
* Binds a the certain context or the active one to the target function and then returns the target
* @param context A context (span) to be bind to target
* @param target a function. When target or one of its callbacks is called,
* the provided context will be used as the active context for the duration of the call.
*/
bind<T>(context: AsyncContext, target: T): T;
}
//# sourceMappingURL=asyncHooksContextManager.d.ts.map