romgrk / node-gtk

GTK+ bindings for NodeJS (via GObject introspection)
MIT License
494 stars 41 forks source link

Event loop improvements #265

Closed romgrk closed 3 years ago

romgrk commented 3 years ago

Closes #121

I don't like that this calls CallMicrotaskHandlers() on every "prepare" step of the glib loop, but it's the only thing that seems to work to fix longstanding promise issues.

Related discussion: https://github.com/nodejs/nan/issues/541 Inspiration for some of the improvements: https://github.com/nodegui/nodegui/blob/2ac83ca8574e484c89e999360a08fb821bce4207/src/lib/core/bootstrap.ts

Qode seems to be a more mature solution, we should look into integrating with it or re-using it eventually.

romgrk commented 3 years ago

macOS tests are failing -_-

If there is someone with a mac who wants to try to debug test/loop.js it would be awesome, put a few console.log statements and see where it blocks. Otherwise I'll keep trying to debug with GHA tomorrow.

wotzlaff commented 3 years ago

Just a quick preview... What I when running the test is the following:

run
activate
realize
clicked
[WARN] closure.cc: Execute: 99: Marshal: return value has invalid g_type
promise:start-before
clicked:settimeout
clicked:promise-settimeout
clicked:promise-resolved

Maybe I can find out more.

wotzlaff commented 3 years ago

Everything seems to be working but const status = app.run([]) does not return. The function onQuit is running but the application does not terminate. Adding a app.quit() in there helps to get the test passing. But this seems to be kindof the wrong thing to do. As I have no clue of Gtk I hope you can evaluate whether this makes sense.

romgrk commented 3 years ago

Actually, using app.quit() makes sense. The manual loop handling is not part of GTK4 C tutorials, it's only required due to integration with nodejs. Not sure why there is a difference between linux & macOS though, but I'm comfortable living with that if it solves our other problems.

romgrk commented 3 years ago

Thanks for looking into this btw :) I always dread fixing macOS/windows bugs as I don't have access to those.

wotzlaff commented 3 years ago

Thank you for looking into the whole event loop issue. I would be lost. And it is not a big deal to start up macOS and try what you implemented ;)