class Async::WorkerPool::Promise
def call
def call work = nil @guard.synchronize do @thread = ::Thread.current return unless work = @work end resolve(work.call) rescue Exception => error reject(error) end
def cancel
def cancel return unless @work @guard.synchronize do @work = nil @state = :cancelled @thread&.raise(Interrupt) end end
def initialize(work)
def initialize(work) @work = work @state = :pending @value = nil @guard = ::Mutex.new @condition = ::ConditionVariable.new @thread = nil end
def reject(error)
def reject(error) synchronize do = nil d = nil = error = :failed tion.broadcast
def resolve(value)
def resolve(value) synchronize do = nil d = nil = value = :resolved tion.broadcast
def wait
def wait @guard.synchronize do while @state == :pending @condition.wait(@guard) end if @state == :failed raise @value else return @value end end end