Hook
declare class Hook<T, R, AdditionalOptions = UnsetAdditionalOptions> {
constructor(args?: ArgumentNames<AsArray<T>>, name?: string);
name: string | undefined;
taps: FullTap[];
intercept(interceptor: HookInterceptor<T, R, AdditionalOptions>): void;
isUsed(): boolean;
callAsync(...args: Append<AsArray<T>, Callback<Error, R>>): void;
promise(...args: AsArray<T>): Promise<R>;
tap(options: string | Tap & IfSet<AdditionalOptions>, fn: (...args: AsArray<T>) => R): void;
withOptions(options: TapOptions & IfSet<AdditionalOptions>): Omit<this, "call" | "callAsync" | "promise">;
}
SyncHook
export class SyncHook<T, R = void, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> {
call(...args: AsArray<T>): R;
}
AsyncHook
declare class AsyncHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> {
tapAsync(
options: string | Tap & IfSet<AdditionalOptions>,
fn: (...args: Append<AsArray<T>, InnerCallback<Error, R>>) => void
): void;
tapPromise(
options: string | Tap & IfSet<AdditionalOptions>,
fn: (...args: AsArray<T>) => Promise<R>
): void;
}
- tapAsync:执行异步钩子中注册的回调函数。这个方法会按顺序异步调用所有注册的回调函数,并在所有回调函数执行完成后调用最终的回调函数