Skip to content

Commit

Permalink
ensure that the matcher runs on the first tick
Browse files Browse the repository at this point in the history
In the past the matcher was only started on the first tick but
nulceo did not wait for its result, so it always looked like the matcher
timed out.

Nulceo already correctly handles this case in case the pattern changes
or the item list was cleared, so we just had to set `cleared` to `true`
when the `Nucleo` instance is created.
  • Loading branch information
pascalkuthe committed Sep 2, 2023
1 parent 68fee46 commit 323a697
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl<T: Sync + Send + 'static> Nucleo<T> {
items: worker.items.clone(),
},
worker: Arc::new(Mutex::new(worker)),
cleared: false,
cleared: true,
notify,
}
}
Expand Down Expand Up @@ -323,12 +323,15 @@ impl<T: Sync + Send + 'static> Nucleo<T> {
self.should_notify.store(false, atomic::Ordering::Relaxed);
let status = self.pattern.status();
let canceled = status != pattern::Status::Unchanged || self.cleared;
let res = self.tick_inner(timeout, canceled, status);
self.cleared = false;
let mut res = self.tick_inner(timeout, canceled, status);
if !canceled {
return res;
}
self.tick_inner(timeout, false, pattern::Status::Unchanged)
self.cleared = false;
let status2 = self.tick_inner(timeout, false, pattern::Status::Unchanged);
res.changed |= status2.changed;
res.running = status2.running;
res
}

fn tick_inner(&mut self, timeout: u64, canceled: bool, status: pattern::Status) -> Status {
Expand Down

0 comments on commit 323a697

Please sign in to comment.