Skip to main content

ScopedRunningProgress

Struct ScopedRunningProgress 

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

Source

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.

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