napi_resolve_deferred


napi_status napi_resolve_deferred(napi_env env,
                                  napi_deferred deferred,
                                  napi_value resolution); 
  • [in] env:调用该 API 时所处的环境。
  • [in] deferred:与之关联的将要解决的承诺的延迟对象。
  • [in] resolution:用于解决该承诺的值。

这个 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.】