Class: Ractor::Dispatch::Future
- Inherits:
-
Object
- Object
- Ractor::Dispatch::Future
- Defined in:
- lib/ractor/dispatch/future.rb
Instance Method Summary collapse
-
#initialize(port) ⇒ Future
constructor
A new instance of Future.
- #resolved? ⇒ Boolean
- #value ⇒ Object
Constructor Details
#initialize(port) ⇒ Future
Returns a new instance of Future.
6 7 8 9 |
# File 'lib/ractor/dispatch/future.rb', line 6 def initialize(port) @port = port @mutex = Mutex.new end |
Instance Method Details
#resolved? ⇒ Boolean
29 30 31 |
# File 'lib/ractor/dispatch/future.rb', line 29 def resolved? @mutex.synchronize { defined?(@resolved) } end |
#value ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ractor/dispatch/future.rb', line 11 def value @mutex.synchronize do unless defined?(@resolved) @resolved = true status, val = @port.receive @port.close if status == :error @error = val else @value = val end end end raise @error if @error @value end |