Skip to content

Need docs on how to interact with the Node event loop when in JVM node #12

@mikehearn

Description

@mikehearn

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:

  1. 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.

  2. 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions