Skip to content

Commit 06fc777

Browse files
committed
Clarify return values
1 parent 07ee51f commit 06fc777

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/concurrent/synchronized_object.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,34 @@ def synchronize
3333
# wait until another thread calls #signal or #broadcast,
3434
# spurious wake-ups can happen.
3535
# @param [Numeric, nil] timeout in seconds, `nil` means no timeout
36+
# @return [self]
3637
def wait(timeout = nil)
3738
synchronize { ns_wait(timeout) }
39+
self
3840
end
3941

4042
# Wait until condition is met or timeout passes,
4143
# protects against spurious wake-ups.
4244
# @param [Numeric, nil] timeout in seconds, `nil` means no timeout
4345
# @yield condition to be met
4446
# @yieldreturn [true, false]
47+
# @return [true, false]
4548
def wait_until(timeout = nil, &condition)
4649
synchronize { ns_wait_until(timeout, &condition) }
4750
end
4851

4952
# signal one waiting thread
53+
# @return [self]
5054
def signal
5155
synchronize { ns_signal }
56+
self
5257
end
5358

5459
# broadcast to all waiting threads
60+
# @return [self]
5561
def broadcast
5662
synchronize { ns_broadcast }
63+
self
5764
end
5865

5966
# @yield condition
@@ -74,21 +81,24 @@ def ns_wait_until(timeout, &condition)
7481
end
7582
end
7683

84+
# @return [self]
7785
def ns_wait(timeout)
7886
raise NotImplementedError
7987
end
8088

89+
# @return [self]
8190
def ns_signal
8291
raise NotImplementedError
8392
end
8493

94+
# @return [self]
8595
def ns_broadcast
8696
raise NotImplementedError
8797
end
8898

8999
end
90100

91-
begin
101+
if Concurrent.on_jruby?
92102
require 'jruby'
93103

94104
# roughly more than 2x faster
@@ -108,18 +118,19 @@ def ns_wait(timeout)
108118
else
109119
JRuby.reference0(self).wait
110120
end
121+
self
111122
end
112123

113124
def ns_broadcast
114125
JRuby.reference0(self).notifyAll
126+
self
115127
end
116128

117129
def ns_signal
118130
JRuby.reference0(self).notify
131+
self
119132
end
120133
end
121-
rescue LoadError
122-
# ignore
123134
end
124135

125136
class MutexSynchronizedObject < AbstractSynchronizedObject
@@ -140,14 +151,17 @@ def synchronize
140151

141152
def ns_signal
142153
@__condition__do_not_use_directly.signal
154+
self
143155
end
144156

145157
def ns_broadcast
146158
@__condition__do_not_use_directly.broadcast
159+
self
147160
end
148161

149162
def ns_wait(timeout)
150163
@__condition__do_not_use_directly.wait @__lock__do_not_use_directly, timeout
164+
self
151165
end
152166
end
153167

0 commit comments

Comments
 (0)