-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed
Description
- Version: v8.4.0
- Platform: Linux 4.13.0-43-generic Improve repo description #48~16.04.1-Ubuntu SMP Thu May 17 12:56:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem: N-API
I can't find a way to pass error from simple async operation back to main loop.
Tests for async calls napi_throw_type_error straight from execute callback, which should run in thread pool. But napi_throw_type_error does not synchronize access to VM, which, AFAIK, is not allowed, by v8 at least.
node/test/addons-napi/test_async/test_async.cc
Lines 23 to 37 in a406a32
| void Execute(napi_env env, void* data) { | |
| #if defined _WIN32 | |
| Sleep(1000); | |
| #else | |
| sleep(1); | |
| #endif | |
| carrier* c = static_cast<carrier*>(data); | |
| if (c != &the_carrier) { | |
| napi_throw_type_error(env, nullptr, "Wrong data parameter to Execute."); | |
| return; | |
| } | |
| c->_output = c->_input * 2; | |
| } |
What is correct way to pass error back? I can make my own variant using data pointer, but something like Nan::AsyncWorker::SetErrorMessage would be nice.
Availability of napi_env in napi_async_execute_callback make things more confusing - it makes me think that I can call any N-API function.
Metadata
Metadata
Assignees
Labels
No labels