Class: ThreadExecutor::Promise

Inherits:
Object
  • Object
show all
Defined in:
lib/thread_executor/promise.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePromise

Returns a new instance of Promise.



43
44
45
46
47
48
49
50
51
# 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

Instance Attribute Details

#exceptionObject

Returns the value of attribute exception.



41
42
43
# File 'lib/thread_executor/promise.rb', line 41

def exception
  @exception
end

#futureObject (readonly)

Returns the value of attribute future.



41
42
43
# File 'lib/thread_executor/promise.rb', line 41

def future
  @future
end

#valueObject

Wait until this Promise is fulfilled and return the value If an exception was raised, it is reraised here.



55
56
57
# File 'lib/thread_executor/promise.rb', line 55

def value
  @value
end

Instance Method Details

#ready?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/thread_executor/promise.rb', line 68

def ready?
  @ready
end