Class: Zoidberg::Future

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

Overview

Perform action and fetch result in the future

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize { ... } ⇒ self

Create a new instance

Yields:

  • block to execute



14
15
16
# File 'lib/zoidberg/future.rb', line 14

def initialize(&block)
  @future = Concurrent::Future.execute(&block)
end

Instance Attribute Details

#futureConcurrent::Future (readonly)

Returns underlying thread running task.

Returns:

  • (Concurrent::Future)

    underlying thread running task



8
9
10
# File 'lib/zoidberg/future.rb', line 8

def future
  @future
end

Instance Method Details

#available?TrueClass, FalseClass

Check if value is available

Returns:

  • (TrueClass, FalseClass)


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

def available?
  future.fulfilled?
end

#valueObject

Returns result value.

Returns:

  • (Object)

    result value



19
20
21
22
23
24
# File 'lib/zoidberg/future.rb', line 19

def value
  unless(@value)
    @value = @future.value
  end
  @value
end