-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
java_count_down_latch.rb
42 lines (36 loc) 路 1.08 KB
/
java_count_down_latch.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
if Concurrent.on_jruby?
module Concurrent
# @!macro count_down_latch
# @!visibility private
# @!macro internal_implementation_note
class JavaCountDownLatch
# @!macro count_down_latch_method_initialize
def initialize(count = 1)
Utility::NativeInteger.ensure_integer_and_bounds(count)
Utility::NativeInteger.ensure_positive(count)
@latch = java.util.concurrent.CountDownLatch.new(count)
end
# @!macro count_down_latch_method_wait
def wait(timeout = nil)
result = nil
if timeout.nil?
Synchronization::JRuby.sleep_interruptibly { @latch.await }
result = true
else
Synchronization::JRuby.sleep_interruptibly do
result = @latch.await(1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS)
end
end
result
end
# @!macro count_down_latch_method_count_down
def count_down
@latch.countDown
end
# @!macro count_down_latch_method_count
def count
@latch.getCount
end
end
end
end