diff --git a/lib/listen/adapter/base.rb b/lib/listen/adapter/base.rb index b75565d3..96956142 100644 --- a/lib/listen/adapter/base.rb +++ b/lib/listen/adapter/base.rb @@ -88,9 +88,8 @@ def stop private def _stop - if thread = @run_thread - thread.kill.join - end + @run_thread&.kill + @run_thread = nil end def _timed(title) diff --git a/lib/listen/adapter/darwin.rb b/lib/listen/adapter/darwin.rb index 0fc8d3b1..a53d6ae8 100644 --- a/lib/listen/adapter/darwin.rb +++ b/lib/listen/adapter/darwin.rb @@ -80,7 +80,7 @@ def _run_worker(worker) end def _stop - @worker_thread.kill.join if (@worker_thread ||= nil) + @worker_thread&.kill super end end diff --git a/lib/listen/event/loop.rb b/lib/listen/event/loop.rb index aa4e3912..43e2050c 100644 --- a/lib/listen/event/loop.rb +++ b/lib/listen/event/loop.rb @@ -68,7 +68,7 @@ def stop transition! :stopped if @wait_thread.alive? - @wait_thread.join.kill + @wait_thread.join end @wait_thread = nil end diff --git a/spec/lib/listen/adapter/polling_spec.rb b/spec/lib/listen/adapter/polling_spec.rb index 4cad580a..b48854bb 100644 --- a/spec/lib/listen/adapter/polling_spec.rb +++ b/spec/lib/listen/adapter/polling_spec.rb @@ -61,7 +61,6 @@ t = Thread.new { subject.start } sleep 0.25 t.kill - t.join end end diff --git a/spec/lib/listen/event/loop_spec.rb b/spec/lib/listen/event/loop_spec.rb index 0d7d633c..749d4351 100644 --- a/spec/lib/listen/event/loop_spec.rb +++ b/spec/lib/listen/event/loop_spec.rb @@ -84,7 +84,7 @@ describe '#stop' do before do - allow(thread).to receive_message_chain(:join, :kill) + allow(thread).to receive(:join) end it 'frees the thread' do @@ -92,7 +92,7 @@ end it 'waits for the thread to finish' do - expect(thread).to receive_message_chain(:join, :kill) + expect(thread).to receive(:join) subject.stop end