-
Notifications
You must be signed in to change notification settings - Fork 289
Closed
Description
As discussed on Slack: https://rust-bindings.slack.com/archives/neon/p1489508576491688.
The basic idea is that a Rust addon can create a continuous background thread that notifies Javascript when things happen (event style).
Psuedo Javascript:
addin.run(function() {
console.log("got the event!")
}
Psuedo Rust:
fn run(call: Call) -> JsResult<JsString> {
let scope = call.scope;
let f = call.arguments.require(scope, 0)?.check::<JsFunction>()?;
thread::spawn(|| {
while (true) {
let args: Vec<Handle<JsNumber>> = vec![];
match f.call(scope, JsNull::new(), args) {
_ => { println!("Call to javascript done!"); }
}
thread::sleep(1000);
}
});
Ok(JsString::new(scope, "hello node").unwrap())
}
If this was achievable it would be a lot nicer than the C equivalent, an example of which is here: https://gist.github.com/matzoe/11082417.
I imagine there would need to be some kind of wrapper around the call, so maybe not completely transparent as shown above.
abrodersen, Aajax0, amilajack, cztomsik, samuelcolvin and 4 more
Metadata
Metadata
Assignees
Labels
No labels