|
|
@ -56,13 +56,16 @@ pub enum CommandKind
|
|
|
|
/// Will respond with `Result<String, IdNotFoundError>` of the removal operation
|
|
|
|
/// Will respond with `Result<String, IdNotFoundError>` of the removal operation
|
|
|
|
RemoveTask(TaskId),
|
|
|
|
RemoveTask(TaskId),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Set the title directly
|
|
|
|
|
|
|
|
SetTitle(String),
|
|
|
|
|
|
|
|
|
|
|
|
Shutdown,
|
|
|
|
Shutdown,
|
|
|
|
|
|
|
|
|
|
|
|
Many(Vec<CommandKind>),
|
|
|
|
Many(Vec<CommandKind>),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The type sent in response to a `Command`.
|
|
|
|
/// The type sent in response to a `Command`.
|
|
|
|
pub type Response = Option<Box<dyn std::any::Any + Send+ Sync + 'static>>;
|
|
|
|
pub type Response = Option<Box<dyn std::any::Any + Send + 'static>>;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum CommandIter
|
|
|
|
enum CommandIter
|
|
|
@ -198,6 +201,14 @@ impl<B: ProgressBar> Handle<B>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
self.send_command(command).await?.await
|
|
|
|
self.send_command(command).await?.await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Send a command to the worker and then wait for it to be processed, then attempt to downcast to type `T`.
|
|
|
|
|
|
|
|
pub async fn send_command_and_downcast<T: 'static>(&mut self, command: CommandKind) -> Result<Option<T>, WorkerCommError>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let resp = self.send_command(command).await?.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(resp.map(|x| x.downcast::<T>().ok().map(|x| *x)).flatten())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Send a command to the worker but do not wait for it to be processed
|
|
|
|
/// Send a command to the worker but do not wait for it to be processed
|
|
|
|
pub async fn send_command_and_detach(&mut self, command: CommandKind) -> Result<(), WorkerCommError>
|
|
|
|
pub async fn send_command_and_detach(&mut self, command: CommandKind) -> Result<(), WorkerCommError>
|
|
|
@ -302,6 +313,14 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
update_bar!($($tt)*);
|
|
|
|
update_bar!($($tt)*);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(title $(std)? $title:ident $($tt:tt)*) => {
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let mut bar = bar.write().await;
|
|
|
|
|
|
|
|
bar.set_title(&$title[..]);
|
|
|
|
|
|
|
|
update_bar!($($tt)*);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
(title $($tt:tt)*) => {
|
|
|
|
(title $($tt:tt)*) => {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let mut bar = bar.write().await;
|
|
|
|
let mut bar = bar.write().await;
|
|
|
@ -405,6 +424,7 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
CommandKind::RemoveTask(id) => {
|
|
|
|
CommandKind::RemoveTask(id) => {
|
|
|
|
send_response!(update_bar!(-task id title));
|
|
|
|
send_response!(update_bar!(-task id title));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::SetTitle(string) => update_bar!(title string),
|
|
|
|
CommandKind::Refresh => update_bar!(refresh),
|
|
|
|
CommandKind::Refresh => update_bar!(refresh),
|
|
|
|
CommandKind::Many(_) => unimplemented!(),
|
|
|
|
CommandKind::Many(_) => unimplemented!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|