pub struct ScopedRunningProgress<'scope> { /* private fields */ }Expand description
Owns a scoped running progress reporter thread.
ScopedRunningProgress is a lifecycle guard for a reporter thread created
by crate::RunningProgressLoop::spawn_scoped. Keep this guard on the
coordinating thread, pass RunningProgressPoints 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,
RunningProgressLoop,
};
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 =
RunningProgressLoop::spawn_scoped(scope, progress, move || {
ProgressCounters::new(Some(1))
.with_completed_count(loop_completed.load(Ordering::Acquire))
});
let progress_points = running_progress.points();
completed.store(1, Ordering::Release);
assert!(progress_points.running_point());
running_progress.stop_and_join();
});§Author
Haixing Hu
Implementations§
Source§impl<'scope> ScopedRunningProgress<'scope>
impl<'scope> ScopedRunningProgress<'scope>
Sourcepub fn points(&self) -> RunningProgressPoints
pub fn points(&self) -> RunningProgressPoints
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 ScopedRunningProgress<'scope>
impl<'scope> !RefUnwindSafe for ScopedRunningProgress<'scope>
impl<'scope> Send for ScopedRunningProgress<'scope>
impl<'scope> Sync for ScopedRunningProgress<'scope>
impl<'scope> Unpin for ScopedRunningProgress<'scope>
impl<'scope> UnsafeUnpin for ScopedRunningProgress<'scope>
impl<'scope> !UnwindSafe for ScopedRunningProgress<'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