Skip to content
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

Weird callback behavior #412

Closed
clayrisser opened this issue Sep 7, 2017 · 3 comments
Closed

Weird callback behavior #412

clayrisser opened this issue Sep 7, 2017 · 3 comments

Comments

@clayrisser
Copy link

I am using a callback with node-ffi, but it is behaving strangely. Some code executes, and some code is just ignored. It's super weird.

app.two = () => { console.log(2); };
app.register_on_activate(ffi.Callback('void', [type.GtkWidgetPtr], (window) => {
  console.log(1);
  app.two();
  console.log(3);
});

The result I get after the callback is 1 3. It completely skips 2. Every time I try and call a function outside of the callback it just ignores it. I have no errors or warnings. Any idea what is going on?

@clayrisser
Copy link
Author

To be more specific, it's when I'm calling the resolve of a promise. For some reason, everything inside the function runs, but the resolve won't run.

return new Promise((resolve, reject) => {
  app.register_on_activate(ffi.Callback('void', [type.GtkWidgetPtr], (window) => {
    console.log(1);
    resolve();
    console.log(3);
  });
}).then(() => {
  // never resolves
  console.log(2);
});

@clayrisser
Copy link
Author

I figured out my problem. I was blocking the JavaScript event loop. You can see more details at the link below.

clayrisser/gtk-node#4

@TooTallNate
Copy link
Member

I'm glad you were able to figure it out ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants