pub struct ProgressTask<R: Copy + 'static> { /* private fields */ }Implementations§
Source§impl<R: Copy + 'static> ProgressTask<R>
impl<R: Copy + 'static> ProgressTask<R>
Sourcepub fn create(
base_path: impl AsRef<Path>,
initial_result: R,
) -> Result<Self, ProgressTaskError>
pub fn create( base_path: impl AsRef<Path>, initial_result: R, ) -> Result<Self, ProgressTaskError>
Create a new ProgressTask at base_path. Allocates four MMF
files; initialises progress=0, total=0, done=false, result=
initial_result.
Sourcepub fn open(base_path: impl AsRef<Path>) -> Result<Self, ProgressTaskError>
pub fn open(base_path: impl AsRef<Path>) -> Result<Self, ProgressTaskError>
Open an existing ProgressTask at base_path. All four MMF
files must exist.
Sourcepub fn begin(&self, total: u64) -> ProgressReporter
pub fn begin(&self, total: u64) -> ProgressReporter
Begin a new task run with the given total denominator.
Resets progress=0, done=false, and publishes total. Returns
a ProgressReporter for the work closure to advance.
Sourcepub fn complete(&self, result: R)
pub fn complete(&self, result: R)
Mark the task complete and publish the final result. Other
processes observing is_done will see true after this call;
read_result returns the published value.
Sourcepub fn fraction_complete(&self) -> f64
pub fn fraction_complete(&self) -> f64
Current fraction in [0.0, 1.0]. Returns 0.0 when total is 0 (no task has begun); clamped at 1.0 to avoid >100% display.
Sourcepub fn current_progress(&self) -> u64
pub fn current_progress(&self) -> u64
Current progress counter value.
Sourcepub fn read_result(&self) -> Option<R>
pub fn read_result(&self) -> Option<R>
Read the most-recently-published result. Returns None when
is_done is false (a result MAY still be there from a prior
completed run, but the current run is not yet finished).
Sourcepub fn peek_result(&self) -> R
pub fn peek_result(&self) -> R
Read the result cell unconditionally. Useful for reading the initial value before any run, or for sampling a stale value.
Sourcepub fn run<F>(&self, total: u64, work: F) -> Rwhere
F: FnOnce(&ProgressReporter) -> R,
pub fn run<F>(&self, total: u64, work: F) -> Rwhere
F: FnOnce(&ProgressReporter) -> R,
Run the work closure synchronously on the calling thread.
Calls begin(total) to set up the reporter, runs the closure,
publishes the result via complete, and returns the result.
Sourcepub fn spawn<F>(self: &Arc<Self>, total: u64, work: F) -> JoinHandle<()>
pub fn spawn<F>(self: &Arc<Self>, total: u64, work: F) -> JoinHandle<()>
Spawn the work closure on a background thread. Returns a
JoinHandle so the caller can wait if desired; the task’s
completion is also visible via is_done.
Sourcepub fn flush(&self) -> Result<(), ProgressTaskError>
pub fn flush(&self) -> Result<(), ProgressTaskError>
Sync all four files to disk.
Sourcepub fn flush_async(&self) -> Result<(), ProgressTaskError>
pub fn flush_async(&self) -> Result<(), ProgressTaskError>
Non-blocking flush of all four files. Delegates to each inner primitive’s flush_async. Note: Windows is only partially async (sync to page cache, not to disk).