asyncHook.enable()


为给定的 AsyncHook 实例启用回调。如果未提供回调,则启用操作不会产生任何效果。

【Enable the callbacks for a given AsyncHook instance. If no callbacks are provided, enabling is a no-op.】

AsyncHook 实例默认是禁用的。如果希望在创建后立即启用 AsyncHook 实例,可以使用以下模式。

【The AsyncHook instance is disabled by default. If the AsyncHook instance should be enabled immediately after creation, the following pattern can be used.】

import { createHook } from 'node:async_hooks';

const hook = createHook(callbacks).enable();const async_hooks = require('node:async_hooks');

const hook = async_hooks.createHook(callbacks).enable();