You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a bit confused by the example that lets you call a JS function within Rust. Having a heck of a time comprehending the Calling JS functions section located at https://neon-bindings.com/docs/functions. Keep in mind I'm early in my Rust learnings (so bear with me).
I've reviewed the documentation but I'm still VERY fuzzy on how to accomplish my need. What I'd like to do is simply: within JS register a function that Rust can call that processes asynchronously. For example:
So within rust I want to call MyLibrary.processRequest({ "foo": "bar" });.
The examples unfortunately aren't commented/descriptive enough for me to understand the process of registering the function within Rust and then at some arbitrary point call the function somewhere in my native plugin.
Basically I'm writing an HTTP server binding with Neon, every request that comes into the HTTP server needs to be processed by Node, the response returned and sent back to the user via Rust.
Any suggestions would be helpful!
PS. I don't need to call a method on a class directly, even if I can register a closure and call it on the Rust side, that should be sufficient.
The text was updated successfully, but these errors were encountered:
davedbase
changed the title
Question: Confused with example to call JS function from Rust
Question: Confused by examples to call JS function from Rust
Dec 27, 2018
Unfortunately, this is not currently possible (#369) since there is no API provided to lock the VM from Rust; it must be initiated by JS. You can work around it by polling (kjvalencik/neon-example@2ef932d).
There are a couple of proposals for implementing this:
If you try the polling approach, keep in mind that this example doesn't include a poll timeout--and it should. If you needed to a create a few instances of this, you would exhaust the libuv threadpool waiting on empty queues.
Aha, that makes a heck of a lot of sense. Hoping this gets added as the polling system imposes a dramatic perf limitation for us. I'll have to work it in for now and pray that the Neon team gets something going for it =) thanks for the great work btw.
I'm a bit confused by the example that lets you call a JS function within Rust. Having a heck of a time comprehending the
Calling JS functions
section located at https://neon-bindings.com/docs/functions. Keep in mind I'm early in my Rust learnings (so bear with me).I've reviewed the documentation but I'm still VERY fuzzy on how to accomplish my need. What I'd like to do is simply: within JS register a function that Rust can call that processes asynchronously. For example:
So within rust I want to call
MyLibrary.processRequest({ "foo": "bar" });
.The examples unfortunately aren't commented/descriptive enough for me to understand the process of registering the function within Rust and then at some arbitrary point call the function somewhere in my native plugin.
Basically I'm writing an HTTP server binding with Neon, every request that comes into the HTTP server needs to be processed by Node, the response returned and sent back to the user via Rust.
Any suggestions would be helpful!
PS. I don't need to call a method on a class directly, even if I can register a closure and call it on the Rust side, that should be sufficient.
The text was updated successfully, but these errors were encountered: