Skip to content

Commit 2a182b4

Browse files
committed
Remove wait, signal, broadcast in favor of ns_ counterparts
- no to pollute the object's space - it can be easily added as noted in documentation
1 parent 6dbfa92 commit 2a182b4

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

lib/concurrent/synchronization/abstract_object.rb

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ def synchronize
4242

4343
private
4444

45-
# wait until another thread calls #signal or #broadcast,
46-
# spurious wake-ups can happen.
47-
# @param [Numeric, nil] timeout in seconds, `nil` means no timeout
48-
# @return [self]
49-
# @note intended to be made public if required in child classes
50-
def wait(timeout = nil)
51-
synchronize { ns_wait(timeout) }
52-
self
53-
end
54-
5545
# initialization of the object called inside synchronize block
5646
def ns_initialize(*args, &block)
5747
end
@@ -61,32 +51,14 @@ def ns_initialize(*args, &block)
6151
# @param [Numeric, nil] timeout in seconds, `nil` means no timeout
6252
# @yield condition to be met
6353
# @yieldreturn [true, false]
64-
# @return [true, false]
65-
# @note intended to be made public if required in child classes
66-
def wait_until(timeout = nil, &condition)
67-
synchronize { ns_wait_until(timeout, &condition) }
68-
end
69-
70-
# signal one waiting thread
71-
# @return [self]
72-
# @note intended to be made public if required in child classes
73-
def signal
74-
synchronize { ns_signal }
75-
self
76-
end
77-
78-
# broadcast to all waiting threads
79-
# @return [self]
80-
# @note intended to be made public if required in child classes
81-
def broadcast
82-
synchronize { ns_broadcast }
83-
self
84-
end
85-
54+
# @return [true, false] if condition met
8655
# @note only to be used inside synchronized block
87-
# @yield condition
88-
# @return [true, false]
89-
# see #wait_until
56+
# @note to provide direct access to this method in a descendant add method
57+
# ```
58+
# def wait_until(timeout = nil, &condition)
59+
# synchronize { ns_wait_until(timeout, &condition) }
60+
# end
61+
# ```
9062
def ns_wait_until(timeout, &condition)
9163
if timeout
9264
wait_until = Concurrent.monotonic_time + timeout
@@ -104,23 +76,44 @@ def ns_wait_until(timeout, &condition)
10476
end
10577
end
10678

107-
# @note only to be used inside synchronized block
79+
# Wait until another thread calls #signal or #broadcast,
80+
# spurious wake-ups can happen.
81+
#
82+
# @param [Numeric, nil] timeout in seconds, `nil` means no timeout
10883
# @return [self]
109-
# @see #wait
84+
# @note only to be used inside synchronized block
85+
# @note to provide direct access to this method in a descendant add method
86+
# ```
87+
# def wait(timeout = nil)
88+
# synchronize { ns_wait(timeout) }
89+
# end
90+
# ```
11091
def ns_wait(timeout = nil)
11192
raise NotImplementedError
11293
end
11394

114-
# @note only to be used inside synchronized block
95+
# Signal one waiting thread
11596
# @return [self]
116-
# @see #signal
97+
# @note only to be used inside synchronized block
98+
# @note to provide direct access to this method in a descendant add method
99+
# ```
100+
# def signal
101+
# synchronize { ns_signal }
102+
# end
103+
# ```
117104
def ns_signal
118105
raise NotImplementedError
119106
end
120107

121-
# @note only to be used inside synchronized block
108+
# Broadcast to all waiting threads
122109
# @return [self]
123-
# @see #broadcast
110+
# @note only to be used inside synchronized block
111+
# @note to provide direct access to this method in a descendant add method
112+
# ```
113+
# def broadcast
114+
# synchronize { ns_broadcast }
115+
# end
116+
# ```
124117
def ns_broadcast
125118
raise NotImplementedError
126119
end

0 commit comments

Comments
 (0)