When using functions from addon blocks the main process node js?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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;
})
- Ngôn ngữ chính
- C++
- Star
- 2.6k
- Fork
- 602
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nodejs/node-addon-examples
-
Create Valgrind run of tests Đang mởenhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
nodejs/node-addon-examples#585 · 1 reaction ·
-
Add .d.ts files in samples. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
nodejs/node-addon-examples#530 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
nodejs/node-addon-examples#445 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 32/100
nodejs/node-addon-examples#444 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
nodejs/node-addon-examples#381 ·
Tất cả issue của nodejs/node-addon-examples
Issue tương tự
-
Website Doc Typo Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 92/100
autowarefoundation/autoware_universe#13413 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
automated-analysis bug memory-safety
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100