romgrk / node-gtk

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

Event loop issues #273

Open romgrk opened 3 years ago

romgrk commented 3 years ago

So a bit more issues with the event loop. Apparently, if we start the glib main loop from within a microtask callback, then all the microtasks created from within this loop will not resolve until the loop exits. I can see why it would do that but maybe we can try to find a way to solve it. Maybe the solution is using qode.

// top-level of the file, works
const app = new Gtk.Application()
app.on('activate', () => { queueMicrotask(() => console.log('called')) })
app.run()
// within a microtask callback, does not work
const app = new Gtk.Application()
app.on('activate', () => { queueMicrotask(() => console.log('called')) })
Promise.resolve().then(() => {
  app.run()
})