Skip to content

Commit

Permalink
perf: doesn't wait for the process of killing (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi authored Sep 9, 2023
1 parent a90adf5 commit 0acf345
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/src/external/jq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub async fn jq(path: &Path, skip: usize, limit: usize) -> Result<String, PeekEr
lines.push('\n');
}

child.start_kill().ok();
if skip > 0 && i < skip + limit {
Err(PeekError::Exceed(i.saturating_sub(limit)))
} else {
Expand Down
8 changes: 3 additions & 5 deletions core/src/external/unar.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{path::Path, process::Stdio};

use anyhow::{bail, Result};
use tokio::{io::{AsyncReadExt, BufReader}, process::Command};
use tokio::{io::AsyncReadExt, process::Command};

pub async fn unar_head(path: &Path, target: &Path) -> Result<Vec<u8>> {
let mut child = Command::new("unar")
Expand All @@ -13,10 +13,8 @@ pub async fn unar_head(path: &Path, target: &Path) -> Result<Vec<u8>> {
.spawn()?;

let mut buf = vec![0; 1024];
let mut reader = BufReader::new(child.stdout.take().unwrap());

reader.read(&mut buf).await.ok();
child.kill().await.ok();
child.stdout.take().unwrap().read(&mut buf).await.ok();
child.start_kill().ok();

if buf.is_empty() {
bail!("failed to get head of unar");
Expand Down

0 comments on commit 0acf345

Please sign in to comment.