by Asooka · 6y ago · 0 comments
> Can you call Rust from JS and JS from Rust?
Yes.
I personally have written some JS code that returns a promise, wrapped in wasm that turned it into a Rust Future, then converted that Future into a promise that I've returned to Javascript.
> If you go JS->Rust->JS->Rust->JS and the innermost JS function throws an exception, is all that properly propagated up the stack?
Sort of. Rust doesn't use exceptions, but the binding converts a JavaScript exception to a Rust "result" type and vice versa at the boundary, so if you propogate it, it will get properly propagated.
I use TypeScript / Svelte for DOM interactions and only call into Rust code for the state updates (treating it like a black box).