From 2f03a2174504f0625589a67f24c6ce123fb103f5 Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Sat, 19 Sep 2020 16:55:48 -0700 Subject: [PATCH] issue #487: only call one of Thread#join, Thread#kill --- lib/listen/adapter/base.rb | 5 ++--- lib/listen/adapter/darwin.rb | 2 +- lib/listen/event/loop.rb | 2 +- spec/lib/listen/adapter/polling_spec.rb | 1 - spec/lib/listen/event/loop_spec.rb | 4 ++-- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/listen/adapter/base.rb b/lib/listen/adapter/base.rb index 8362cddd..e29988f0 100644 --- a/lib/listen/adapter/base.rb +++ b/lib/listen/adapter/base.rb @@ -86,9 +86,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 39a29ee7..89d217b6 100644 --- a/lib/listen/adapter/darwin.rb +++ b/lib/listen/adapter/darwin.rb @@ -78,7 +78,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 d1c35efc..01696c49 100644 --- a/lib/listen/event/loop.rb +++ b/lib/listen/event/loop.rb @@ -66,7 +66,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 ade5e9ee..1ff40443 100644 --- a/spec/lib/listen/adapter/polling_spec.rb +++ b/spec/lib/listen/adapter/polling_spec.rb @@ -59,7 +59,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 4e758a38..9e1b1f26 100644 --- a/spec/lib/listen/event/loop_spec.rb +++ b/spec/lib/listen/event/loop_spec.rb @@ -82,7 +82,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 @@ -90,7 +90,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