Class: LiveResource::Future

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

Overview

Returned from async method calls, in order to later get a method’s return value.

Instance Method Summary collapse

Constructor Details

#initialize(proxy, method) ⇒ Future

Returns a new instance of Future.



5
6
7
8
9
# File 'lib/live_resource/methods/future.rb', line 5

def initialize(proxy, method)
  @proxy = proxy
  @method = method
  @value = nil
end

Instance Method Details

#done?Boolean

Returns:

  • (Boolean)


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

def done?
  if @value.nil?
    @proxy.done_with? @method
  else
    true
  end
end

#value(timeout = 0) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/live_resource/methods/future.rb', line 11

def value(timeout = 0)
  if @value.nil?
    @value = @proxy.wait_for_done(@method, timeout)
  end

  @value
end