perf: doesn't wait for the process of killing (#128)

This commit is contained in:
三咲雅 · Misaki Masa 2023-09-09 23:03:47 +08:00 committed by GitHub
parent a90adf5bc5
commit 0acf345ee3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 5 deletions

View file

@ -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 {

View file

@ -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")
@ -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");