Skip to main content

RunningProgressGuard

Struct RunningProgressGuard 

Source
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>

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.