class Async::WorkerPool::Worker

A background worker thread.

def call(work)

Call the work and notify the scheduler when it is done.
def call(work)
	promise = Promise.new(work)
	
	@work.push(promise)
	
	begin
		return promise.wait
	ensure
		promise.cancel
	end
end

def close

Close the worker thread.
def close
	if thread = @thread
		@thread = nil
		thread.kill
	end
end

def initialize

Create a new worker.
def initialize
	@work = ::Thread::Queue.new
	@thread = ::Thread.new(&method(:run))
end

def run

Execute work until the queue is closed.
def run
	while work = @work.pop
		work.call
	end
end