|
|
@ -200,27 +200,25 @@ impl<B: ProgressBar> Handle<B>
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// # Notes
|
|
|
|
/// # Notes
|
|
|
|
/// Acquiring this will prevent the worker from exiting until the closure finishes.
|
|
|
|
/// Acquiring this will prevent the worker from exiting until the closure finishes.
|
|
|
|
pub async fn with_bar_mut<F,T, Fn>(&self, fun: F) -> Result<T, WorkerCommError>
|
|
|
|
pub async fn with_bar_mut<F,T>(&self, fun: F) -> Result<T, WorkerCommError>
|
|
|
|
where F: FnOnce(&'_ mut B) -> Fn,
|
|
|
|
where F: FnOnce(&'_ mut B) -> T,
|
|
|
|
Fn: Future<Output=T>
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let handle = self.bar.upgrade().ok_or(WorkerCommError)?;
|
|
|
|
let handle = self.bar.upgrade().ok_or(WorkerCommError)?;
|
|
|
|
let mut h = handle.write().await;
|
|
|
|
let mut h = handle.write().await;
|
|
|
|
use std::ops::DerefMut;
|
|
|
|
use std::ops::DerefMut;
|
|
|
|
Ok(fun(h.deref_mut()).await)
|
|
|
|
Ok(fun(h.deref_mut()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// Act on a reference to the bar within this closure
|
|
|
|
/// Act on a reference to the bar within this closure
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// # Notes
|
|
|
|
/// # Notes
|
|
|
|
/// Acquiring this will prevent the worker from exiting until the closure finishes.
|
|
|
|
/// Acquiring this will prevent the worker from exiting until the closure finishes.
|
|
|
|
pub async fn with_bar<F,T, Fn>(&self, fun: F) -> Result<T, WorkerCommError>
|
|
|
|
pub async fn with_bar<F,T>(&self, fun: F) -> Result<T, WorkerCommError>
|
|
|
|
where F: FnOnce(&'_ B) -> Fn,
|
|
|
|
where F: FnOnce(&'_ B) -> T,
|
|
|
|
Fn: Future<Output=T>
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let handle = self.bar.upgrade().ok_or(WorkerCommError)?;
|
|
|
|
let handle = self.bar.upgrade().ok_or(WorkerCommError)?;
|
|
|
|
let h = handle.read().await;
|
|
|
|
let h = handle.read().await;
|
|
|
|
use std::ops::Deref;
|
|
|
|
use std::ops::Deref;
|
|
|
|
Ok(fun(h.deref()).await)
|
|
|
|
Ok(fun(h.deref()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -228,6 +226,7 @@ impl<B: ProgressBar> Handle<B>
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct WorkerCommError;
|
|
|
|
pub struct WorkerCommError;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl error::Error for WorkerCommError{}
|
|
|
|
impl fmt::Display for WorkerCommError
|
|
|
|
impl fmt::Display for WorkerCommError
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
|
|