class Async::WorkerPool
@private
A simple work pool that offloads work to a background thread.
def call(work)
Offload work to a thread.
def call(work) if ready = @ready worker = ready.pop begin worker.call(work) ensure ready.push(worker) end else raise RuntimeError, "No worker available!" end end
def close
def close if ready = @ready @ready = nil ready.close while worker = ready.pop worker.close end end end
def initialize(size: Etc.nprocessors)
Create a new work pool.
def initialize(size: Etc.nprocessors) @ready = ::Thread::Queue.new size.times do @ready.push(Worker.new) end end