summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlali <luteran42@outlook.com>2023-09-26 19:11:51 +0200
committerGitHub <noreply@github.com>2023-09-26 13:11:51 -0400
commita6a1d7b386cbecaad84e026bba8f9725aa3ca07f (patch)
treeaea68d11fa5e7bc3f3e7aba35922d9bd543c679a
parent1db44e06f183376ebcce11c9c8fa3babe2884000 (diff)
fix: add mutex lock to preview threads (#430)
* [fix] add mutex lock to preview threads Do not spawn 100s of threads when I'm holding down the arrow key. * [fix] add mutex lock to preview threads Do not spawn 100s of threads when I'm holding down the arrow key.
-rw-r--r--src/preview/preview_file.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/preview/preview_file.rs b/src/preview/preview_file.rs
index 96fccb3..9b4194a 100644
--- a/src/preview/preview_file.rs
+++ b/src/preview/preview_file.rs
@@ -1,5 +1,6 @@
use std::path;
use std::process::{Command, Output};
+use std::sync::Mutex;
use std::thread;
use std::time;
@@ -7,8 +8,13 @@ use ratatui::layout::Rect;
use crate::context::AppContext;
use crate::event::AppEvent;
+use crate::lazy_static;
use crate::ui::{views, AppBackend};
+lazy_static! {
+ static ref GUARD: Mutex<()> = Mutex::new(());
+}
+
pub enum PreviewFileState {
Loading,
Error { message: String },
@@ -79,6 +85,7 @@ impl Background {
.insert(path.clone(), PreviewFileState::Loading);
let _ = thread::spawn(move || {
+ let _locked = GUARD.lock().unwrap();
let file_full_path = path.as_path();
let res = Command::new(script)