aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ts/tskm/src/task/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/ts/tskm/src/task/mod.rs')
-rw-r--r--pkgs/by-name/ts/tskm/src/task/mod.rs60
1 files changed, 33 insertions, 27 deletions
diff --git a/pkgs/by-name/ts/tskm/src/task/mod.rs b/pkgs/by-name/ts/tskm/src/task/mod.rs
index 5e223e33..1362615d 100644
--- a/pkgs/by-name/ts/tskm/src/task/mod.rs
+++ b/pkgs/by-name/ts/tskm/src/task/mod.rs
@@ -10,14 +10,14 @@
use std::{
fmt::Display,
- fs::{self, File, read_to_string},
+ fs::{self, read_to_string, File},
path::PathBuf,
process::Command,
str::FromStr,
sync::OnceLock,
};
-use anyhow::{Context, Result, bail};
+use anyhow::{bail, Context, Result};
use log::{debug, info, trace};
use taskchampion::Tag;
@@ -45,18 +45,20 @@ impl From<&taskchampion::TaskData> for Task {
}
impl Task {
- pub fn from_working_set(id: usize, state: &mut State) -> Result<Option<Self>> {
+ pub async fn from_working_set(id: usize, state: &mut State) -> Result<Option<Self>> {
Ok(state
.replica()
- .working_set()?
+ .working_set()
+ .await?
.by_index(id)
.map(|uuid| Self { uuid }))
}
- pub fn get_current(state: &mut State) -> Result<Option<Self>> {
+ pub async fn get_current(state: &mut State) -> Result<Option<Self>> {
let tasks = state
.replica()
- .pending_tasks()?
+ .pending_tasks()
+ .await?
.into_iter()
.filter(taskchampion::Task::is_active)
.collect::<Vec<_>>();
@@ -76,62 +78,65 @@ impl Task {
pub fn uuid(&self) -> &taskchampion::Uuid {
&self.uuid
}
- pub fn working_set_id(&self, state: &mut State) -> Result<usize> {
+ pub async fn working_set_id(&self, state: &mut State) -> Result<usize> {
Ok(state
.replica()
- .working_set()?
+ .working_set()
+ .await?
.by_uuid(self.uuid)
.expect("The task should be in the working set"))
}
- fn as_task(&self, state: &mut State) -> Result<taskchampion::Task> {
+ async fn as_task(&self, state: &mut State) -> Result<taskchampion::Task> {
Ok(state
.replica()
- .get_task(self.uuid)?
+ .get_task(self.uuid)
+ .await?
.expect("We have the task from this replica, it should still be in it"))
}
/// Adds a tag to the task, to show the user that it has additional neorg data.
- pub fn mark_neorg_data(&self, state: &mut State) -> Result<()> {
+ pub async fn mark_neorg_data(&self, state: &mut State) -> Result<()> {
let mut ops = vec![];
- self.as_task(state)?
+ self.as_task(state)
+ .await?
.add_tag(&Tag::from_str("neorg_data").expect("Is valid"), &mut ops)?;
- state.replica().commit_operations(ops)?;
+ state.replica().commit_operations(ops).await?;
Ok(())
}
/// Try to start this task.
/// It will stop previously active tasks.
- pub fn start(&self, state: &mut State) -> Result<()> {
+ pub async fn start(&self, state: &mut State) -> Result<()> {
info!("Activating {self}");
- if let Some(active) = Self::get_current(state)? {
- active.stop(state)?;
+ if let Some(active) = Self::get_current(state).await? {
+ active.stop(state).await?;
}
let mut ops = vec![];
- self.as_task(state)?.start(&mut ops)?;
- state.replica().commit_operations(ops)?;
+ self.as_task(state).await?.start(&mut ops)?;
+ state.replica().commit_operations(ops).await?;
Ok(())
}
/// Stops this task.
- pub fn stop(&self, state: &mut State) -> Result<()> {
+ pub async fn stop(&self, state: &mut State) -> Result<()> {
info!("Stopping {self}");
let mut ops = vec![];
- self.as_task(state)?.stop(&mut ops)?;
- state.replica().commit_operations(ops)?;
+ self.as_task(state).await?.stop(&mut ops)?;
+ state.replica().commit_operations(ops).await?;
Ok(())
}
- pub fn description(&self, state: &mut State) -> Result<String> {
- Ok(self.as_task(state)?.get_description().to_owned())
+ pub async fn description(&self, state: &mut State) -> Result<String> {
+ Ok(self.as_task(state).await?.get_description().to_owned())
}
- pub fn project(&self, state: &mut State) -> Result<Project> {
+ pub async fn project(&self, state: &mut State) -> Result<Project> {
let output = {
- let task = self.as_task(state)?;
+ let task = self.as_task(state).await?;
let task_data = task.into_task_data();
task_data
.get("project")
@@ -303,10 +308,11 @@ impl Project {
/// # Errors
/// When `task` execution fails.
- pub fn get_tasks(&self, state: &mut State) -> Result<Vec<Task>> {
+ pub async fn get_tasks(&self, state: &mut State) -> Result<Vec<Task>> {
Ok(state
.replica()
- .pending_task_data()?
+ .pending_task_data()
+ .await?
.into_iter()
.filter(|t| t.get("project").expect("Is set") == self.to_project_display())
.map(|t| Task::from(&t))