Skip to content

Commit

Permalink
migrate to tokio for asynchronous processing
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaa committed Aug 30, 2023
1 parent 31beaab commit 80f95c1
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 49 deletions.
181 changes: 176 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ version = "^0"
default-features = false
features = ["termion"]

[dependencies.tokio]
version = "^1"
features = [ "full" ]

[dependencies.uuid]
version = "^1"
features = ["v4", "fast-rng", "macro-diagnostics"]
Expand Down
8 changes: 4 additions & 4 deletions src/commands/delete_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use termion::event::Key;
use crate::context::AppContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::history::DirectoryHistory;
use crate::io::{FileOperation, FileOperationOptions, IoWorkerThread};
use crate::io::{FileOperation, FileOperationOptions, IoWorkerTask};
use crate::ui::widgets::TuiPrompt;
use crate::ui::AppBackend;

Expand Down Expand Up @@ -49,12 +49,12 @@ fn delete_files(
};

let dest = path::PathBuf::new();
let worker_thread = IoWorkerThread::new(file_op, paths.clone(), dest, options);
let worker_task = IoWorkerTask::new(file_op, paths.clone(), dest, options);
if background {
context.worker_context_mut().push_worker(worker_thread);
context.worker_context_mut().push_worker(worker_task);
} else {
let (wtx, _) = mpsc::channel();
worker_thread.start(wtx)?;
worker_task.start(wtx)?;
}

let history = context.tab_context_mut().curr_tab_mut().history_mut();
Expand Down
6 changes: 3 additions & 3 deletions src/commands/file_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::process::{Command, Stdio};

use crate::context::{AppContext, LocalStateContext};
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::io::{FileOperation, FileOperationOptions, IoWorkerThread};
use crate::io::{FileOperation, FileOperationOptions, IoWorkerTask};

fn new_local_state(context: &mut AppContext, file_op: FileOperation) -> Option<()> {
let list = context.tab_context_ref().curr_tab_ref().curr_list_ref()?;
Expand Down Expand Up @@ -41,8 +41,8 @@ pub fn paste(context: &mut AppContext, options: FileOperationOptions) -> Joshuto
match context.take_local_state() {
Some(state) if !state.paths.is_empty() => {
let dest = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf();
let worker_thread = IoWorkerThread::new(state.file_op, state.paths, dest, options);
context.worker_context_mut().push_worker(worker_thread);
let worker_task = IoWorkerTask::new(state.file_op, state.paths, dest, options);
context.worker_context_mut().push_worker(worker_task);
Ok(())
}
_ => Err(JoshutoError::new(
Expand Down
Loading

0 comments on commit 80f95c1

Please sign in to comment.