模块注册
// queue_work.cpp
EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
{ “queueWork”, nullptr, QueueWork, nullptr, nullptr, nullptr, napi_default, nullptr }
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
return exports;
}
EXTERN_C_END
static napi_module nativeModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = Init,
.nm_modname = “queue_work”,
.nm_priv = nullptr,
.reserved = { 0 },
};
extern “C” attribute((constructor)) void RegisterQueueWorkModule()
{
napi_module_register(&nativeModule);
}
- 获取env对应的loop,并抛任务到ArkTS线程
// queue_work.cpp
#include
#inc