node.js - async_hooks - 为什么没有调用/清理资源
问题描述
以下代码
import async_hooks from 'async_hooks'
console.log(`father: "${async_hooks.triggerAsyncId()}" - current: "${async_hooks.executionAsyncId()}"`)
const asyncHook = async_hooks.createHook({
init(asyncId, type, triggerAsyncId, resource) {
console.log(`creating - father: "${triggerAsyncId}" - current: "${asyncId}"`, {
type,
resource,
})
},
destroy(asyncId) {
console.log(`destroying - "${asyncId}"`)
},
})
asyncHook.enable()
打印以下标准输出:
father: "0" - current: "1"
destroying - "4"
creating - father: "0" - current: "5" {
type: 'TickObject',
resource: {
callback: [Function: afterWriteTick],
args: [ [Object] ],
[Symbol(async_id_symbol)]: 5,
[Symbol(trigger_async_id_symbol)]: 0
}
}
✨ Done in 2.22s.
问题:
- 什么是“4”?
- 什么是“TickObject”以及为什么在 Node.js 退出之前不清理“5”?
- 与
console.log
异步一样,我希望 async_hooks 将永远被调用。为什么我在输出中看不到无限递归?
解决方案
推荐阅读
- android - 如何将货币转换器添加到我的颤动到我的与 woocommerce 链接的电子商务应用程序
- sql - 如果有人更改了他们的用户名,GitHub 应用程序的最佳实践?
- amazon-web-services - aws 在 cloudwatch 警报上调用 lambda - 仅此帐户的电子邮件列表可用
- binary - 一个 32 位内存位置保存单个数据项,如图所示
- reactjs - 在类组件中反应交集观察者
- security - 如何在 ec2 实例中保护文件夹密码?
- android - 为什么我的否定按钮出现在警报对话框的左侧?
- c# - 尝试在 MVC 中创建可排序表
- http - nginx:将http重定向到https,得到错误结果www.www.domain.com
- python - 无法控制360连续伺服电机FS5106R