pub fn call<O>(f: impl FnMut() -> O) -> OAvailable on crate feature
hotpatching only.Expand description
Call a given function with hot-reloading enabled. If the function’s code changes, call will use
the new version of the function. If code above the function changes, this will emit a panic
that forces an unwind to the next call instance.
WASM/rust does not support unwinding, so call will not track dependency graph changes.
If you are building a framework for use on WASM, you will need to use Subsecond::HotFn directly.
However, if you wrap your calling code in a future, you can simply drop the future which will
cause drop to execute and get something similar to unwinding. Not great if refcells are open.
Examples found in repository?
examples/ecs/hotpatching_systems.rs (line 88)
81fn start_thread(receiver: crossbeam_channel::Receiver<()>) {
82 std::thread::spawn(move || {
83 while receiver.recv().is_ok() {
84 let start = bevy::platform::time::Instant::now();
85
86 // You can also make any part outside of a system hot patchable by wrapping it
87 // In this part, only the duration is hot patchable:
88 let duration = bevy::app::hotpatch::call(|| Duration::from_secs(2));
89
90 std::thread::sleep(duration);
91 info!("done after {:?}", start.elapsed());
92 }
93 });
94}