rscarson / rustyscript

Effortless JS integration for rust
MIT License
168 stars 18 forks source link

Add shutdown_background_tokio_runtime to Runtime #171

Closed mocchira closed 2 months ago

mocchira commented 2 months ago

As described at a comment included in this PR, Now library users are not able to call tokio runtime's shutdown_background because it's wrapped by Rc.

There are some use cases for users to call shutdown_background from within another tokio runtime like using with tonic so IMHO adding shutdown_background_tokio_runtime looks reasonable.

rscarson commented 2 months ago

There may be some value in making it more general How would you feel about an into_tokio_runtime that consumes the self and returns the runtime instead?

You could still use shutdown_background but it would not tie down other possible use-cases

mocchira commented 2 months ago

There may be some value in making it more general How would you feel about an into_tokio_runtime that consumes the self and returns the runtime instead? You could still use shutdown_background but it would not tie down other possible use-cases

Sounds good! I will update the PR as suggested.

rscarson commented 2 months ago

I'd also prefer your function return the Option instead of unwrapping

rscarson commented 2 months ago

Is this still something you are interested in?

mocchira commented 2 months ago

Sorry for the late reply. Now I'm tackling the problem that using rustyscript on tonic doesn't work as expected sometimes. This PR is one of the fix to make it however it has gradually turned out that running rustyscript on tonic's tokio runtime can cause some trouble so I gonna try to use WorkerPlool.

rscarson commented 2 months ago

What're the issues you encountered? It may be helpful for yourself and others in the same position if you open a discussion post detailing the problem

In the meantime, given how trivial this change is I will close this pr for now and add an into_tokio_runtime or something in the version being released tomorrow

mocchira commented 2 months ago

What're the issues you encountered? It may be helpful for yourself and others in the same position if you open a discussion post detailing the problem

After get the point, I'll open a discussion post:)