napi_value theFunc = nullptr;
if (napi_get_named_property(env, promise, “then”, &theFunc) != napi_ok) {
return nullptr;
}
napi_value resolvedCallback = nullptr;
napi_value rejectedCallback = nullptr;
napi_create_function(env, “resolvedCallback”, NAPI_AUTO_LENGTH, ResolvedCallback, nullptr, &resolvedCallback);
napi_create_function(env, “rejectedCallback”, NAPI_AUTO_LENGTH, RejectedCallback, nullptr, &rejectedCallback);
napi_value argv[2] = {resolvedCallback, rejectedCallback};
napi_call_function(env, promise, theFunc, 2, argv, nullptr);
auto flag = reinterpret_cast<bool *>(arg);
if (*flag == true) {
napi_run_event_loop(env, napi_event_mode_default);
} else {
// 非阻塞式的处理任务,有可能队列中还没有任务就已经返回了
napi_run_event_loop(env, napi_event_mode_nowait);
}
return nullptr;
}
static napi_value RunEventLoo