nodejs / node-addon-api Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Electron addon: Napi::AsyncWorker does not work #1087
Comments
|
I'm having no issues w/ AsyncWorker w/ ipcMain calling my addon. Could you post the code you're using? |
|
@mithusingh32 I reproduced it on https://github.com/nodejs/node-addon-examples/tree/main/napi-asyncworker-example/node-addon-api. Just added electron, electron-rebuild, electron-mocha, and ran the following commands. |
|
I also tried it with the updated node-addon-api 4.2.0, it didn't help. |
|
The log you provided, is that when you're seeing the issue or when its working? Because the makes me think that AsyncWorker is working. |
|
@mithusingh32 No, in the example these are synchronous responses of |
|
Weird. |
|
|
I mean the actual method call within your app. |
|
I don't really understand the question. I have the addon written in C++ which has an api that looks exactly like the I also found out that AsyncWorker doesn't work since electron version 8.5.2. |
|
@codebytere can you comment if there is anything on the electron side that might explain why it does not work in electron versus working in Node.js itself? |
|
If i'm understanding right and this is running in the renderer process, it's the case that we integrate the event loop from Node.js into that of Chromium, so there are subtle bugs like this that can arise from time to time. i'll try to see what's going on with it when i have some time! |
|
I just ran into this issue as well. I am using electron 16.0.4.0 on Windows. For me the My Is there any way I can detect when electron will quit from Node.js side and run code there? If I manually stop the worker via interacting in a specific way with my app, quitting doesn't result in any crash. |
|
Never mind figured it out. this.exitEvent.on('exit', async () => {
if (!this.reader.isStopped) await this.reader.Stop();
app.quit();
});
this.mainWindow.once('close', (event) => {
event.preventDefault();
this.exitEvent.emit('exit');
return undefined;
});It might not cover all the possible exit scenarios, but it will do for now for my use case. I might make an example later of how I use |
|
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Hello!
I am trying to migrate native module for electron application from nan to napi using addon-node-api wrapper. I am facing a problem with AsyncWorker. Overridden Execute works fine and gets results, but OnOK is never called. Under debugging I realized that the OnAsyncWorkComplete callback is never called. I downloaded the examples (https://github.com/nodejs/node-addon-examples), built a napi-asyncworker-example for electron and got the same result. If you build under node and run on it, everything works fine.
I've tried electron 15.1.1, 15.1.0, 14.1.0
The text was updated successfully, but these errors were encountered: