When using functions from addon blocks the main process node js?
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with the readDataSerial N-API wrapper shown in the issue and trace the blocking Ibox_Controller_ReadData call. Review the Node.js addon guidance for asynchronous work, then determine how the result is delivered without blocking the main process. Done means the long-running read no longer prevents the Node.js main thread from processing other work.
Written by the indexing model from the issue text.
Description
Implemented a wrapper for the function using N-API. It works, but the problem is that when it works the main thread of the node does not work? How can I rewrite this function so that it does not block the main thread? What do I need to use async, callback, thread for this?
napi_value readDataSerial(napi_env env, napi_callback_info info) {
napi_status status;
size_t argc = 1;
napi_value args[1], object;
napi_value id, data;
status = napi_get_cb_info(env, info, &argc, args, NULL, NULL);
assert(status == napi_ok);
if (argc < 1) {
napi_throw_type_error(env, NULL, "Wrong number of arguments");
return NULL;
}
//....
Ibox_ReadData *context = calloc(1, sizeof(Ibox_Context));
//this function takes a long time and blocks the main process
Ibox_Result_Submit *submitResult = Ibox_Controller_ReadData(context);
status = napi_create_object(env, &object);
status = napi_create_string_utf8(env, submitResult->id, NAPI_AUTO_LENGTH, &id);
status = napi_set_named_property(env, object, "id", id);
status = napi_create_string_utf8(env, submitResult->date, NAPI_AUTO_LENGTH, &date);
status = napi_set_named_property(env, object, "data", data);
assert(status == napi_ok);
return object;
})
- Dominant language
- C++
- Stars
- 2.6k
- Forks
- 602
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nodejs/node-addon-examples
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 38/100
nodejs/node-addon-examples#585 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
nodejs/node-addon-examples#530 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
nodejs/node-addon-examples#445 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 32/100
nodejs/node-addon-examples#444 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
nodejs/node-addon-examples#381 ·
All issues in nodejs/node-addon-examples
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Sensor initialization takes very long when `--initial-sim-time` is set to current UNIX timestamp Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gazebosim/gz-sensors#662 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
LadybirdBrowser/ladybird#12123 ·