pub struct RunningProgressGuard<'scope> { /* private fields */ }Expand description
Owns a scoped running progress reporter thread.
RunningProgressGuard is created by
Progress::spawn_running_reporter.
Keep this guard on the coordinating thread, pass
RunningProgressPointHandle clones to workers, and call
Self::stop_and_join after worker execution completes.
§Examples
use std::{
sync::{
Arc,
atomic::{
AtomicUsize,
Ordering,
},
},
thread,
time::Duration,
};
use qubit_progress::{
NoOpProgressReporter,
Progress,
ProgressCounters,
};
let reporter = NoOpProgressReporter;
let completed = Arc::new(AtomicUsize::new(0));
thread::scope(|scope| {
let loop_completed = Arc::clone(&completed);
let progress = Progress::new(&reporter, Duration::ZERO);
let running_progress =
progress.spawn_running_reporter(scope, move || {
ProgressCounters::new(Some(3))
.with_completed_count(loop_completed.load(Ordering::Acquire))
});
let progress_point_handle = running_progress.point_handle();
let mut handles = Vec::new();
for _ in 0..3 {
let c = Arc::clone(&completed);
let p = progress_point_handle.clone();
handles.push(scope.spawn(move || {
c.fetch_add(1, Ordering::AcqRel);
assert!(p.report());
}));
}
for h in handles {
h.join().unwrap();
}
running_progress.stop_and_join();
});§Author
Haixing Hu
Implementations§
Source§impl<'scope> RunningProgressGuard<'scope>
impl<'scope> RunningProgressGuard<'scope>
Sourcepub fn point_handle(&self) -> RunningProgressPointHandle
pub fn point_handle(&self) -> RunningProgressPointHandle
Returns a worker-side running point handle.
§Returns
A cloneable handle that wakes the reporter loop for zero intervals and becomes a no-op for positive intervals.
Sourcepub fn stop_and_join(self)
pub fn stop_and_join(self)
Stops the reporter loop and joins the scoped reporter thread.
§Panics
Propagates any panic raised by the reporter thread.
Auto Trait Implementations§
impl<'scope> Freeze for RunningProgressGuard<'scope>
impl<'scope> !RefUnwindSafe for RunningProgressGuard<'scope>
impl<'scope> Send for RunningProgressGuard<'scope>
impl<'scope> Sync for RunningProgressGuard<'scope>
impl<'scope> Unpin for RunningProgressGuard<'scope>
impl<'scope> UnsafeUnpin for RunningProgressGuard<'scope>
impl<'scope> !UnwindSafe for RunningProgressGuard<'scope>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more