resource


resource 是一个对象,表示已初始化的实际异步资源。这可能包含有用的信息,这些信息可能会因 type 的值而异。例如,对于 GETADDRINFOREQWRAP 资源类型,resource 提供在 net.Server.listen() 中查找主机 IP 地址时使用的主机名。不支持访问此信息的 API,但使用 Embedder API,用户可以提供和记录他们自己的资源对象。例如,这样的资源对象可以包含正在执行的 SQL 查询。

¥resource is an object that represents the actual async resource that has been initialized. This can contain useful information that can vary based on the value of type. For instance, for the GETADDRINFOREQWRAP resource type, resource provides the host name used when looking up the IP address for the host in net.Server.listen(). The API for accessing this information is not supported, but using the Embedder API, users can provide and document their own resource objects. For example, such a resource object could contain the SQL query being executed.

在某些情况下,出于性能原因,资源对象会被重用,因此将其用作 WeakMap 中的键或向其添加属性是不安全的。

¥In some cases the resource object is reused for performance reasons, it is thus not safe to use it as a key in a WeakMap or add properties to it.