When using functions from addon blocks the main process node js?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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;
})
- Lingua principale
- C++
- Stelle
- 2.6k
- Fork
- 602
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nodejs/node-addon-examples
-
Create Valgrind run of tests Apertaenhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
nodejs/node-addon-examples#585 · 1 reazione ·
-
Add .d.ts files in samples. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
nodejs/node-addon-examples#530 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
nodejs/node-addon-examples#445 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 32/100
nodejs/node-addon-examples#444 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
nodejs/node-addon-examples#381 ·
Tutte le issue di nodejs/node-addon-examples
Issue simili
-
Website Doc Typo Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 92/100
autowarefoundation/autoware_universe#13413 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
automated-analysis bug memory-safety
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100