process.finalization.registerBeforeExit(ref, callback)


稳定性: 1.1 - 积极开发

¥Stability: 1.1 - Active Development

  • ref <Object> | <Function> 对正在跟踪的资源的引用。

    ¥ref <Object> | <Function> The reference to the resource that is being tracked.

  • callback <Function> 资源最终确定后要调用的回调函数。

    ¥callback <Function> The callback function to be called when the resource is finalized.

    • ref <Object> | <Function> 对正在跟踪的资源的引用。

      ¥ref <Object> | <Function> The reference to the resource that is being tracked.

    • event <string> 触发最终确定的事件。默认为 'beforeExit'。

      ¥event <string> The event that triggered the finalization. Defaults to 'beforeExit'.

此函数的行为与 register 完全相同,不同之处在于,如果 ref 对象未被垃圾收集,则在进程触发 beforeExit 事件时将调用回调。

¥This function behaves exactly like the register, except that the callback will be called when the process emits the beforeExit event if ref object was not garbage collected.

请注意,应用于 beforeExit 事件的所有限制也适用于 callback 函数,这意味着在特殊情况下可能不会调用回调。

¥Be aware that all limitations applied to the beforeExit event are also applied to the callback function, this means that there is a possibility that the callback will not be called under special circumstances.