Skip to content

N-API: pass error from execute callback in napi_create_async_work to main loop #20964

Closed
@mcheshkov

Description

@mcheshkov
  • 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.

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions