Open Rjvs opened 5 years ago
@adamjs JS <-> C++ Promises could make an excellent addition to the Tutorials you're working on.
Hi Robert,
Finally got around to investigating this, I modified Tutorial 4 to use Promises instead and had the C++ callback immediately invoke the Resolve function without any issues. I've shared the code in a Gist:
https://gist.github.com/adamjs/d689ad6d291a1cdd4e923c63a66cc22d
Please test it out and see if your results are the same (the app should display 'Hello' after you click the button).
Are you using the C API / JavaScriptCore API or the AppCore JSHelpers API? Which platform are you on? (I tested on Windows 10)
Also, after the C++ callback is invoked, are you caching the Resolve function for asynchronous invocation later? (I tested this too and was successful however I did find a bug in AppCore's JSFunction implementation-- any cached JSFunctions that are returned from a JS callback need to have their JSContextRef's replaced with the View's main JSContextRef otherwise JavaScriptCore will crash. I'm going to fix.).
Thanks Adam. Using a combination of the C API and AppCore JSHelpers, concentrating on Win10.
I'll take a closer look through the Gist and see what we're doing differently.
We are trying to make JS promises that are fulfilled in C but we seem to need to create an extra event to kick the event loop, which is a little inelegant. Are we missing something?
Example: