rksm / hot-lib-reloader-rs

Reload Rust code without app restarts. For faster feedback cycles.
MIT License
577 stars 21 forks source link

[Feature request] Only reload on request #17

Closed jjant closed 1 year ago

jjant commented 1 year ago

I'm writing a sort of game engine and I would like to be able to only reload game code on request (say, when a user presses Cmd+R). Is this currently possible with the library? I couldn't figure it out.

Thanks!

rksm commented 1 year ago

You can block reloads like it is done here: https://github.com/rksm/hot-lib-reloader-rs/blob/master/tests/lib-loader-test.rs#L48. As long as you don't drop the update_blocker token no update will happen, potentially indefinitely. The reload event example shows how you can do this in a separate async task (or with thread it work the same).

You can build a mechanism around that to block updates by default and then when a key is pressed you drop the token (if there is one) so that the update will run.