Skip to content

Commit 7e89414

Browse files
committed
Better mutex handling in Async mixin.
1 parent 4a14c11 commit 7e89414

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/concurrent/async.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ def validate_argc(obj, method, *args)
108108
# @!visibility private
109109
class AwaitDelegator # :nodoc:
110110

111-
# The lock used when delegating methods to the wrapped object.
112-
attr_reader :mutex
113-
114111
# Create a new delegator object wrapping the given +delegate+ and
115112
# protecting it with the given +mutex+.
116113
#
@@ -153,16 +150,18 @@ def method_missing(method, *args, &block)
153150

154151
self.send(method, *args)
155152
end
153+
154+
# The lock used when delegating methods to the wrapped object.
155+
#
156+
# @!visibility private
157+
attr_reader :mutex # :nodoc:
156158
end
157159

158160
# Delegates asynchronous, thread-safe method calls to the wrapped object.
159161
#
160162
# @!visibility private
161163
class AsyncDelegator # :nodoc:
162164

163-
# The lock used when delegating methods to the wrapped object.
164-
attr_reader :mutex
165-
166165
# Create a new delegator object wrapping the given +delegate+ and
167166
# protecting it with the given +mutex+.
168167
#
@@ -199,6 +198,13 @@ def method_missing(method, *args, &block)
199198

200199
self.send(method, *args)
201200
end
201+
202+
private
203+
204+
# The lock used when delegating methods to the wrapped object.
205+
#
206+
# @!visibility private
207+
attr_reader :mutex # :nodoc:
202208
end
203209

204210
# Causes the chained method call to be performed asynchronously on the
@@ -229,7 +235,7 @@ def method_missing(method, *args, &block)
229235
#
230236
# @see Concurrent::Future
231237
def async
232-
@__async_delegator__ ||= AsyncDelegator.new(self, Mutex.new)
238+
@__async_delegator__ ||= AsyncDelegator.new(self, await.mutex)
233239
end
234240
alias_method :future, :async
235241

@@ -261,7 +267,7 @@ def async
261267
#
262268
# @see Concurrent::IVar
263269
def await
264-
@__await_delegator__ ||= AwaitDelegator.new(self, async.mutex)
270+
@__await_delegator__ ||= AwaitDelegator.new(self, Mutex.new)
265271
end
266272
alias_method :defer, :await
267273
end

0 commit comments

Comments
 (0)