pub fn with_progress_handler<R>(
handler: impl FnMut(&str, f64) -> ControlFlow<()> + 'static,
body: impl FnOnce() -> R,
) -> RExpand description
Runs body with handler installed as the progress handler of the
calling thread, restoring the previous handler afterwards (even if body
panics). See set_progress_handler.
ยงExamples
use igraph::misc;
use std::{cell::Cell, ops::ControlFlow, rc::Rc};
let calls = Rc::new(Cell::new(0));
let counter = Rc::clone(&calls);
let stopped = misc::with_progress_handler(
move |_, _| {
counter.set(counter.get() + 1);
ControlFlow::Break(()) // please stop
},
|| misc::progress("step", 10.0),
);
assert_eq!(stopped.unwrap_err().kind(), igraph::ErrorKind::Interrupted);
assert_eq!(calls.get(), 1);