fix(find): plugin never successfully interrupting
This commit is contained in:
parent
95e96c8958
commit
f7823707fc
1 changed files with 32 additions and 23 deletions
|
|
@ -11,6 +11,7 @@ use std::rc::Rc;
|
||||||
use tokio::io::AsyncBufReadExt;
|
use tokio::io::AsyncBufReadExt;
|
||||||
use tokio::process::{Child, ChildStdout, Command};
|
use tokio::process::{Child, ChildStdout, Command};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
enum Event {
|
enum Event {
|
||||||
Activate(u32),
|
Activate(u32),
|
||||||
Search(String),
|
Search(String),
|
||||||
|
|
@ -63,7 +64,6 @@ pub async fn main() {
|
||||||
let tx = interrupt_tx.clone();
|
let tx = interrupt_tx.clone();
|
||||||
async move {
|
async move {
|
||||||
if active.get() {
|
if active.get() {
|
||||||
tracing::debug!("sending interrupt");
|
|
||||||
let _ = tx.try_send(());
|
let _ = tx.try_send(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -145,8 +145,6 @@ impl SearchContext {
|
||||||
/// Submits the query to `fdfind` and actively monitors the search results while handling interrupts.
|
/// Submits the query to `fdfind` and actively monitors the search results while handling interrupts.
|
||||||
async fn search(&mut self, search: String) {
|
async fn search(&mut self, search: String) {
|
||||||
self.search_results.clear();
|
self.search_results.clear();
|
||||||
tracing::debug!("searching for {}", search);
|
|
||||||
|
|
||||||
let (mut child, mut stdout) = match query(&search).await {
|
let (mut child, mut stdout) = match query(&search).await {
|
||||||
Ok((child, stdout)) => (child, tokio::io::BufReader::new(stdout).lines()),
|
Ok((child, stdout)) => (child, tokio::io::BufReader::new(stdout).lines()),
|
||||||
Err(why) => {
|
Err(why) => {
|
||||||
|
|
@ -170,6 +168,11 @@ impl SearchContext {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let timeout = async {
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
|
||||||
|
};
|
||||||
|
|
||||||
|
let listener = async {
|
||||||
let mut id = 0;
|
let mut id = 0;
|
||||||
let mut append;
|
let mut append;
|
||||||
|
|
||||||
|
|
@ -196,8 +199,14 @@ impl SearchContext {
|
||||||
break 'stream;
|
break 'stream;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let _ = child.kill();
|
futures::pin_mut!(timeout);
|
||||||
|
futures::pin_mut!(listener);
|
||||||
|
|
||||||
|
let _ = futures::future::select(timeout, listener).await;
|
||||||
|
|
||||||
|
let _ = child.kill().await;
|
||||||
let _ = child.wait().await;
|
let _ = child.wait().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue