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

@ -27,7 +27,10 @@ use std::{
};
mod tasklist;
pub use tasklist::TaskId;
pub use tasklist::{
TaskId,
IdNotFoundError,
};
/// Command to send to worker task.
#[derive(Debug)]
@ -39,7 +42,15 @@ pub enum CommandKind
Bump(isize),
BumpHigh(isize),
/// Add a task to the tasklist
///
/// # Response
/// Will respond with the task's `TaskId`.
AddTask(String),
/// Remove a task from the tasklist.
///
/// # Response
/// Will respond with `Result<String, IdNotFoundError>` of the removal operation
RemoveTask(TaskId),
Shutdown,
@ -184,12 +195,32 @@ impl<B: ProgressBar> Handle<B>
self.state.read().await
}
/// Get an upgraded reference to the bar itself, if it still exists.
/// Act on a mutable 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_mut<F,T, Fn>(&self, fun: F) -> Result<T, WorkerCommError>
where F: FnOnce(&'_ mut B) -> Fn,
Fn: Future<Output=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)
}
/// Act on a reference to the bar within this closure
///
/// This kinda messes things up... Hiding for now.
async fn bar_ref(&self) -> Result<BarRef<B>, WorkerCommError>
/// # 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>
{
Ok(BarRef(self.bar.upgrade().ok_or(WorkerCommError)?))
let handle = self.bar.upgrade().ok_or(WorkerCommError)?;
let h = handle.read().await;
use std::ops::Deref;
Ok(fun(h.deref()).await)
}
}

Loading…
Cancel
Save