Skip to content

Commit ff994f6

Browse files
committed
JavaExecutor#wait_for_termination now honors a nil timeout (wait forever).
1 parent 06dc588 commit ff994f6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/concurrent/executor/executor.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,13 @@ def shutdown?
250250
end
251251

252252
# @!macro executor_method_wait_for_termination
253-
def wait_for_termination(timeout)
254-
@executor.awaitTermination(1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS)
253+
def wait_for_termination(timeout = nil)
254+
if timeout.nil?
255+
ok = @executor.awaitTermination(60, java.util.concurrent.TimeUnit::SECONDS) until ok
256+
true
257+
else
258+
@executor.awaitTermination(1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS)
259+
end
255260
end
256261

257262
# @!macro executor_method_shutdown

spec/concurrent/executor/executor_service_shared.rb

+7
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,12 @@
178178
expect(subject.wait_for_termination(0)).to be_falsey
179179
end
180180
end
181+
182+
it 'waits forever when no timeout value is given' do
183+
subject.post{ sleep(0.5) }
184+
sleep(0.1)
185+
subject.shutdown
186+
expect(subject.wait_for_termination).to be_truthy
187+
end
181188
end
182189
end

0 commit comments

Comments
 (0)