napi_resolve_deferred


napi_status napi_resolve_deferred(napi_env env,
                                  napi_deferred deferred,
                                  napi_value resolution); 
  • [in] env:调用 API 的环境。

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

  • [in] deferred:要解析其关联 promise 的延迟对象。

    ¥[in] deferred: The deferred object whose associated promise to resolve.

  • [in] resolution:用于解决 promise 的值。

    ¥[in] resolution: The value with which to resolve the promise.

此 API 通过与其关联的延迟对象来解析 JavaScript promise。因此,它只能用于解析相应延迟对象可用的 JavaScript promise。这实际上意味着 promise 必须是使用 napi_create_promise() 创建的,并且必须保留从该调用返回的延迟对象才能传递给此 API。

¥This API resolves a JavaScript promise by way of the deferred object with which it is associated. Thus, it can only be used to resolve JavaScript promises for which the corresponding deferred object is available. This effectively means that the promise must have been created using napi_create_promise() and the deferred object returned from that call must have been retained in order to be passed to this API.

延迟对象在成功完成后被释放。

¥The deferred object is freed upon successful completion.