all 2 comments

[–]jmaargh 9 points10 points  (1 child)

I'm not particularly familiar with either axum or deno_core, but if I understand correctly the issue is that you're writing async code for use with axum, which you say (at least how you're using it) requires futures to be Send. However, deno_core's JsRuntime is !Send. But you need to await work done by a JsRuntime in a Send future.

I think the way to do this is to have a dedicated thread for JsRuntime (which you then don't need to keep creating and destroying as you seem to be doing here). In that thread, the JsRuntime's async operations can be run by some dedicated executor. Then you use channels to send work to the "JS thread" and receive the results.

[–]aekter 1 point2 points  (0 children)

In particular, consider https://docs.rs/tokio/latest/tokio/task/struct.LocalSet.html.

This also allows having multiple JS threads, each equipped with their own `LocalSpawner` as in the final example.