class Async::Pool::Controller
def initialize(constructor, limit: nil, concurrency: (limit || 1), policy: nil, tags: nil)
@parameter concurrency [Integer] The maximum number of concurrent tasks that can be creating a new resource.
@parameter limit [Integer | Nil] The maximum number of resources that this pool can have at any given time. If nil, the pool can have an unlimited number of resources.
@parameter constructor [Proc] A block which creates a new resource.
Create a new resource pool.
def initialize(constructor, limit: nil, concurrency: (limit || 1), policy: nil, tags: nil) @constructor = constructor @limit = limit # This semaphore is used to limit the number of concurrent tasks which are creating new resources. @guard = Async::Semaphore.new(concurrency) @policy = policy @gardener = nil @tags = tags # All available resources: @resources = {} # Resources which may be available to be acquired: # This list may contain false positives, or resources which were okay but have since entered a state which is unusuable. @available = [] # Used to signal when a resource has been released: @notification = Async::Notification.new end