with_bar no longer takes a future

progress
Avril 4 years ago
parent 98ff368fe8
commit 58643b6440
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -200,27 +200,25 @@ impl<B: ProgressBar> Handle<B>
///
/// # Notes
/// 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>
where F: FnOnce(&'_ mut B) -> Fn,
Fn: Future<Output=T>
pub async fn with_bar_mut<F,T>(&self, fun: F) -> Result<T, WorkerCommError>
where F: FnOnce(&'_ mut B) -> T,
{
let handle = self.bar.upgrade().ok_or(WorkerCommError)?;
let mut h = handle.write().await;
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
///
/// # Notes
/// 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>
where F: FnOnce(&'_ B) -> Fn,
Fn: Future<Output=T>
pub async fn with_bar<F,T>(&self, fun: F) -> Result<T, WorkerCommError>
where F: FnOnce(&'_ B) -> T,
{
let handle = self.bar.upgrade().ok_or(WorkerCommError)?;
let h = handle.read().await;
use std::ops::Deref;
Ok(fun(h.deref()).await)
Ok(fun(h.deref()))
}
}
@ -228,6 +226,7 @@ impl<B: ProgressBar> Handle<B>
#[derive(Debug)]
pub struct WorkerCommError;
impl error::Error for WorkerCommError{}
impl fmt::Display for WorkerCommError
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result

Loading…
Cancel
Save