lib/async/http/pool.rb in async-http-0.48.2 vs lib/async/http/pool.rb in async-http-0.49.0
- old
+ new
@@ -43,20 +43,21 @@
@available = Async::Notification.new
@limit = limit
@constructor = block
+ @guard = Async::Semaphore.new(1)
end
# The number of allocated resources.
def active
@resources.count
end
# Whether there are resources which are currently in use.
def busy?
- @resources.collect do |_,usage|
+ @resources.collect do |_, usage|
return true if usage > 0
end
return false
end
@@ -136,10 +137,14 @@
@available.wait
end
Async.logger.debug(self) {"Wait for resource #{resource}"}
+ if resource.multiplex
+ @available.signal
+ end
+
return resource
end
def create
# This might return nil, which means creating the resource failed.
@@ -163,13 +168,15 @@
retire(resource)
end
end
end
- if !@limit or self.active < @limit
- Async.logger.debug(self) {"No resources resources, allocating new one..."}
-
- return create
+ @guard.acquire do
+ if @limit.nil? or self.active < @limit
+ Async.logger.debug(self) {"No resources resources, allocating new one..."}
+
+ return create
+ end
end
return nil
end
end