process.ref(maybeRefable)


稳定性: 1 - 实验性

  • maybeRefable <any> 一个可能是“可引用”的对象。

如果一个对象实现了 Node.js 的“Refable 协议”,则该对象是“可引用的”。 具体而言,这意味着该对象实现了 Symbol.for('nodejs.ref')Symbol.for('nodejs.unref') 方法。“已引用”的对象会保持 Node.js 事件循环运行,而“未引用”的对象则不会。历史上,这通常是通过在对象上直接使用 ref()unref() 方法来实现的。然而,这种模式正在被废弃,取而代之的是“Refable 协议”,以更好地支持那些 API 无法修改以添加 ref()unref() 方法,但仍需要支持此行为的 Web 平台 API 类型。

【An object is "refable" if it implements the Node.js "Refable protocol". Specifically, this means that the object implements the Symbol.for('nodejs.ref') and Symbol.for('nodejs.unref') methods. "Ref'd" objects will keep the Node.js event loop alive, while "unref'd" objects will not. Historically, this was implemented by using ref() and unref() methods directly on the objects. This pattern, however, is being deprecated in favor of the "Refable protocol" in order to better support Web Platform API types whose APIs cannot be modified to add ref() and unref() methods but still need to support that behavior.】