Class: Ractor::Dispatch::Future

Inherits:
Object
  • Object
show all
Defined in:
lib/ractor/dispatch/future.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


29
30
31
# File 'lib/ractor/dispatch/future.rb', line 29

def resolved?
  @mutex.synchronize { defined?(@resolved) }
end

#valueObject

Raises:

  • (@error)


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