node_api_post_finalizer


稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

napi_status node_api_post_finalizer(node_api_basic_env env,
                                    napi_finalize finalize_cb,
                                    void* finalize_data,
                                    void* finalize_hint); 
  • [in] env:调用 API 的环境。

    ¥[in] env: The environment that the API is invoked under.

  • [in] finalize_cb:当 JavaScript 对象被垃圾回收时,将用于释放原生数据的原生回调。napi_finalize 提供了更多详细信息。

    ¥[in] finalize_cb: Native callback that will be used to free the native data when the JavaScript object has been garbage-collected. napi_finalize provides more details.

  • [in] finalize_data:要传递给 finalize_cb 的可选数据。

    ¥[in] finalize_data: Optional data to be passed to finalize_cb.

  • [in] finalize_hint:传递给完成回调的可选上下文提示。

    ¥[in] finalize_hint: Optional contextual hint that is passed to the finalize callback.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

安排在事件循环中异步调用 napi_finalize 回调。

¥Schedules a napi_finalize callback to be called asynchronously in the event loop.

通常,当 GC(垃圾收集器)收集对象时,会调用终结器。届时,调用任何可能导致 GC 状态发生变化的 Node-API 将被禁用,并使 Node.js 崩溃。

¥Normally, finalizers are called while the GC (garbage collector) collects objects. At that point calling any Node-API that may cause changes in the GC state will be disabled and will crash Node.js.

node_api_post_finalizer 通过允许附加组件将对此类 Node-API 的调用推迟到 GC 最终确定之外的时间点来帮助解决此限制。

¥node_api_post_finalizer helps to work around this limitation by allowing the add-on to defer calls to such Node-APIs to a point in time outside of the GC finalization.