Skip to content

Commit 48f20c6

Browse files
committed
Fix edge Event#wait timeout on ruby 1.9.3
The Monitor#synchronize method catches the break signals, causing the timeouts not to work (just looping forever)
1 parent d4fc3a8 commit 48f20c6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/concurrent/edge/future.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ def wait_until_complete(timeout)
345345
# ok only if completing thread did not start signaling
346346
next unless @Waiters.compare_and_push last_waiter, Thread.current
347347
ns_wait_until(timeout) { completed? }
348-
break
349348
end
349+
break
350350
end
351351
self
352352
end

spec/concurrent/edge/future_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@
171171
expect([queue.pop, queue.pop, queue.pop, queue.pop].sort).to eq [:async, :async, :sync, :sync]
172172
end
173173

174+
it 'supports setting timeout while waiting' do
175+
start_latch = Concurrent::CountDownLatch.new
176+
end_latch = Concurrent::CountDownLatch.new
177+
178+
future = Concurrent.future do
179+
start_latch.count_down
180+
end_latch.wait(1)
181+
end
182+
183+
start_latch.wait(1)
184+
future.wait(0.1)
185+
expect(future).not_to be_completed
186+
end_latch.count_down
187+
future.wait
188+
end
189+
174190
it 'chains' do
175191
future0 = Concurrent.future { 1 }.then { |v| v + 2 } # both executed on default FAST_EXECUTOR
176192
future1 = future0.then(:fast) { raise 'boo' } # executed on IO_EXECUTOR

0 commit comments

Comments
 (0)