From b3f84ae3c56d4ce51d722dcea72de0d0fbb0adcf Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Tue, 6 Jan 2026 13:24:44 +0000 Subject: [PATCH 1/2] - Fix filewatcher interrupt --- lib/bashly/watch.rb | 9 ++++++++- spec/bashly/watch_spec.rb | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/bashly/watch.rb b/lib/bashly/watch.rb index f4b53e0c..cf83e1c2 100644 --- a/lib/bashly/watch.rb +++ b/lib/bashly/watch.rb @@ -46,7 +46,14 @@ def changes(modified, added, removed) { modified:, added:, removed: } end + def wait + sleep + rescue ::Interrupt => e + raise e if e.is_a?(Bashly::Interrupt) + + raise Bashly::Interrupt, cause: e + end + def listen = Listen - def wait = sleep end end diff --git a/spec/bashly/watch_spec.rb b/spec/bashly/watch_spec.rb index 830eea15..c295e577 100644 --- a/spec/bashly/watch_spec.rb +++ b/spec/bashly/watch_spec.rb @@ -55,6 +55,15 @@ end end + context 'when the watch is interrupted' do + it 'stops the listener and re-raises as Bashly::Interrupt' do + allow(subject).to receive(:sleep).and_raise(Interrupt) + + expect(listener).to receive(:stop) + expect { subject.on_change { |_| nil } }.to raise_error(Bashly::Interrupt) + end + end + context 'when no block is provided' do it 'raises ArgumentError' do expect { subject.on_change }.to raise_error(ArgumentError, 'block required') From db07febf3ae42adf4b8c37927c9a0857b21da8cc Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Tue, 6 Jan 2026 13:28:43 +0000 Subject: [PATCH 2/2] remove unnecessary guard --- lib/bashly/watch.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/bashly/watch.rb b/lib/bashly/watch.rb index cf83e1c2..a33ba2de 100644 --- a/lib/bashly/watch.rb +++ b/lib/bashly/watch.rb @@ -49,8 +49,6 @@ def changes(modified, added, removed) def wait sleep rescue ::Interrupt => e - raise e if e.is_a?(Bashly::Interrupt) - raise Bashly::Interrupt, cause: e end