-
Notifications
You must be signed in to change notification settings - Fork 201
Description
I read the docs but I still am unclear on a few things.
If I use node --jvm
and my program starts in Javascript context, then I call into Java to create a Java main thread to run a Java program, how can I call back and forth between those two threads - how can I submit work to the node event loop? (a node event loop? i assume we can only have one!)
For example, assume I have a JavaFX app and I'd like to use node modules from it. AFAICT there are two ways to do this:
-
Implement the core NodeJS API on top of the JVM. Disadvantage: lots of work, may not help with modules that use native code, advantage: presumably the Node event loop could be precisely controlled e.g. integrated with a Netty or JavaFX event loop.
-
Allow Node to start up the JVM and control the main thread, start a separate thread to run my Java main method on. Advantage: works with graaljs as it is now. Disadvantage: using JS code might require a blocking call into the node event loop.
With (2), if I break the rules and use the JS in a multi-threaded way and call it on a separate non-Node thread, what happens if I lose my bet and the code wants to register a callback on the libuv event loop? Do I get an error?
Some samples and docs would go a long way here.