Skip to content

Commit

Permalink
fix(worker): log worker errors instead of exiting thread
Browse files Browse the repository at this point in the history
  • Loading branch information
myypo committed Aug 18, 2024
1 parent fc30482 commit 5ed68af
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion compass/src/functions/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn get_setup(mut tracker: SyncTracker) -> impl FnOnce(Option<Config>) -> Res
apply_highlights(HighlightList::default())?;

let worker = Worker::new(conf.tracker.enable.then_some(tracker));
worker.run_jobs()?;
worker.run_jobs();

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions compass/src/state/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Tracker {
.skip(io + 1)
.filter(|(_, r)| r.buf == buf && r.lazy_extmark.pos(buf.clone()).is_nearby(&p))
{
let _ = ri.lazy_extmark.delete(buf.clone());
ri.lazy_extmark.delete(buf.clone())?;

if let Some(ii) = ii.checked_sub(1) {
list_idx.push(ii);
Expand Down Expand Up @@ -205,7 +205,7 @@ impl Tracker {
.iter_from_future()
.any(|r| r.buf == buf && Some(id) == r.lazy_extmark.id())
{
let _ = buf.del_extmark(ns_id, id);
buf.del_extmark(ns_id, id)?;
}
}

Expand Down
22 changes: 17 additions & 5 deletions compass/src/state/worker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use nvim_oxi::api::{notify, opts::NotifyOpts, types::LogLevel};

use crate::{config::get_config, Result};
use std::time::Instant;

Expand All @@ -17,15 +19,15 @@ impl Worker {
Self { tracker }
}

pub fn run_jobs(mut self) -> Result<()> {
std::thread::spawn(move || -> Result<()> {
pub fn run_jobs(mut self) {
std::thread::spawn(move || {
let debounce = &get_config().tracker.debounce_milliseconds;
let min_deb = min!(debounce.run, debounce.maintenance, debounce.show);

let mut run_inst = Instant::now();
let mut maint_inst = Instant::now();

loop {
let mut jobs = || -> Result<()> {
let now = Instant::now();

if now.duration_since(run_inst) >= debounce.run {
Expand All @@ -46,10 +48,20 @@ impl Worker {
tracker.show()?;
};

Ok(())
};

loop {
if let Err(e) = jobs() {
let _ = notify(
&e.to_string(),
LogLevel::Error,
&NotifyOpts::builder().build(),
);
};

std::thread::sleep(min_deb);
}
});

Ok(())
}
}

0 comments on commit 5ed68af

Please sign in to comment.