type


type 是字符串,标识导致调用 init 的资源类型。 一般会对应资源的构造函数名。

由 Node.js 本身创建的 type 资源可以在任何 Node.js 版本中更改。 有效值包括 TLSWRAPTCPWRAPTCPSERVERWRAPGETADDRINFOREQWRAPFSREQCALLBACKMicrotaskTimeout。 检查用于获取完整列表的 Node.js 版本的源代码。

AsyncResource 的进一步用户创建独立于 Node.js 本身的异步资源。

还有 PROMISE 资源类型,用于跟踪 Promise 实例以及它们调度的异步工作。

用户可以在使用公共嵌入器 API 时定义自己的 type

可能存在类型名称冲突。 鼓励嵌入器使用唯一的前缀,例如 npm 包名,以防止在监听钩子时发生冲突。

The type is a string identifying the type of resource that caused init to be called. Generally, it will correspond to the name of the resource's constructor.

The type of resources created by Node.js itself can change in any Node.js release. Valid values include TLSWRAP, TCPWRAP, TCPSERVERWRAP, GETADDRINFOREQWRAP, FSREQCALLBACK, Microtask, and Timeout. Inspect the source code of the Node.js version used to get the full list.

Furthermore users of AsyncResource create async resources independent of Node.js itself.

There is also the PROMISE resource type, which is used to track Promise instances and asynchronous work scheduled by them.

Users are able to define their own type when using the public embedder API.

It is possible to have type name collisions. Embedders are encouraged to use unique prefixes, such as the npm package name, to prevent collisions when listening to the hooks.