type
type 是一个字符串,用于标识导致调用 init 的资源类型。通常,它会对应于该资源构造函数的名称。
【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.】
Node.js 本身创建的资源的 type 可以在任何 Node.js 版本中发生变化。有效值包括 TLSWRAP、TCPWRAP、TCPSERVERWRAP、GETADDRINFOREQWRAP、FSREQCALLBACK、Microtask 和 Timeout。请检查所使用 Node.js 版本的源代码以获取完整列表。
【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.】
此外,AsyncResource 的用户可以创建独立于 Node.js 本身的异步资源。
【Furthermore users of AsyncResource create async resources independent
of Node.js itself.】
还有一种 PROMISE 资源类型,用于跟踪 Promise 实例及其安排的异步工作。
【There is also the PROMISE resource type, which is used to track Promise
instances and asynchronous work scheduled by them.】
用户在使用公共嵌入器 API 时能够定义自己的 type。
【Users are able to define their own type when using the public embedder API.】
类型名称可能会发生冲突。建议使用者使用唯一前缀,例如 npm 包名,以防在监听钩子时发生冲突。
【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.】