|
|
@ -27,7 +27,10 @@ use std::{
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mod tasklist;
|
|
|
|
mod tasklist;
|
|
|
|
pub use tasklist::TaskId;
|
|
|
|
pub use tasklist::{
|
|
|
|
|
|
|
|
TaskId,
|
|
|
|
|
|
|
|
IdNotFoundError,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Command to send to worker task.
|
|
|
|
/// Command to send to worker task.
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
@ -39,7 +42,15 @@ pub enum CommandKind
|
|
|
|
Bump(isize),
|
|
|
|
Bump(isize),
|
|
|
|
BumpHigh(isize),
|
|
|
|
BumpHigh(isize),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Add a task to the tasklist
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// # Response
|
|
|
|
|
|
|
|
/// Will respond with the task's `TaskId`.
|
|
|
|
AddTask(String),
|
|
|
|
AddTask(String),
|
|
|
|
|
|
|
|
/// Remove a task from the tasklist.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// # Response
|
|
|
|
|
|
|
|
/// Will respond with `Result<String, IdNotFoundError>` of the removal operation
|
|
|
|
RemoveTask(TaskId),
|
|
|
|
RemoveTask(TaskId),
|
|
|
|
|
|
|
|
|
|
|
|
Shutdown,
|
|
|
|
Shutdown,
|
|
|
@ -184,12 +195,32 @@ impl<B: ProgressBar> Handle<B>
|
|
|
|
self.state.read().await
|
|
|
|
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.
|
|
|
|
/// # Notes
|
|
|
|
async fn bar_ref(&self) -> Result<BarRef<B>, WorkerCommError>
|
|
|
|
/// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|