class ThreadExecutor::Promise

A Promise is a container for a value that a Processor will compute.

It contains locking objects to ensure that the value is communicated safely from the Processor 's Thread to user's Thread.

A user typically never touches this object directly but examines the Future.

Attributes

exception[R]
future[R]
value[R]

Public Class Methods

new() click to toggle source
# File lib/thread_executor/promise.rb, line 43
def initialize()
  @value     = nil
  @exception = nil
  @ready     = false
  @lock      = Mutex.new
  @cond      = ConditionVariable.new
  @no_result = true
  @future    = Future.new(self)
end

Public Instance Methods

exception=(e) click to toggle source
# File lib/thread_executor/promise.rb, line 80
def exception= e
  @lock.synchronize do
    @exception = e
    @ready = true
    @cond.signal
  end
end
ready?() click to toggle source
# File lib/thread_executor/promise.rb, line 68
def ready?
  @ready
end
value=(v) click to toggle source
# File lib/thread_executor/promise.rb, line 72
def value= v
  @lock.synchronize do
    @value = v
    @ready = true
    @cond.signal
  end
end