Struct hot_lib_reloader::LibReloadObserver
source · pub struct LibReloadObserver { /* private fields */ }
Expand description
A LibReloadObserver
allows to wait for library changes. See
You can use those methods individually or in combination. In particular, if you want to serialize state before a library change happens and then deserialize / migrate it when the library update is done, using both methods in combination is quite useful. Something along the lines of:
#[hot_module(dylib = "lib")]
mod hot_lib {
#[lib_change_subscription]
pub fn subscribe() -> hot_lib_reloader::LibReloadObserver { }
}
fn test() {
let lib_observer = hot_lib::subscribe();
/* ... */
// wait for reload to begin (at this point the old version is still loaded)
let update_blocker = lib_observer.wait_for_about_to_reload();
/* do update preparations here, e.g. serialize state */
// drop the blocker to allow update
drop(update_blocker);
// wait for reload to be completed
lib_observer.wait_for_reload();
/* new lib version is loaded now so you can e.g. restore state */
}
Implementations§
source§impl LibReloadObserver
impl LibReloadObserver
sourcepub fn wait_for_about_to_reload(&self) -> BlockReload
pub fn wait_for_about_to_reload(&self) -> BlockReload
A call to this method will do a blocking wait until the watched library is
about to change. It returns a BlockReload
token. While this token is in
scope you will prevent the pending update to proceed. This is useful for
doing preparations for the update and while the old library version is still
loaded. You can for example serialize state.
sourcepub fn wait_for_about_to_reload_timeout(
&self,
timeout: Duration
) -> Option<BlockReload>
pub fn wait_for_about_to_reload_timeout( &self, timeout: Duration ) -> Option<BlockReload>
Like Self::wait_for_about_to_reload
but for a limited time. In case of a timeout return None
.
sourcepub fn wait_for_reload(&self)
pub fn wait_for_reload(&self)
Will do blocking wait until a new library version is loaded.
sourcepub fn wait_for_reload_timeout(&self, timeout: Duration) -> bool
pub fn wait_for_reload_timeout(&self, timeout: Duration) -> bool
Like Self::wait_for_reload
but for a limited time. In case of a timeout return false
.