Skip to content

Commit

Permalink
issue guard#487: only call one of Thread#join, Thread#kill
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDKelley committed Oct 29, 2020
1 parent 7d76cc9 commit de1e7cb
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions lib/listen/adapter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/adapter/darwin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/event/loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def stop
transition! :stopped

if @wait_thread.alive?
@wait_thread.join.kill
@wait_thread.join
end
@wait_thread = nil
end
Expand Down
1 change: 0 additions & 1 deletion spec/lib/listen/adapter/polling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
t = Thread.new { subject.start }
sleep 0.25
t.kill
t.join
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/listen/event/loop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@

describe '#stop' do
before do
allow(thread).to receive_message_chain(:join, :kill)
allow(thread).to receive(:join)
end

it 'frees the thread' do
subject.stop
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

Expand Down

0 comments on commit de1e7cb

Please sign in to comment.