Class: Concurrent::Polling::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/concurrent/polling.rb

Instance Method Summary collapse

Constructor Details

#initialize(poll_function, check_function) ⇒ Solver

Returns a new instance of Solver.



23
24
25
26
# File 'lib/concurrent/polling.rb', line 23

def initialize(poll_function, check_function)
  @poll_function = poll_function
  @check_function = check_function
end

Instance Method Details

#solve(result) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/concurrent/polling.rb', line 28

def solve(result)

  condition_met = begin
    @check_function.call(result.ok)
  rescue Exception => e
    raise ConditionError.new(e)
  end

  if(condition_met)
    result
  elsif result.retries == 0
    raise TimeoutError.new
  else

    future = Concurrent::Future.new(&@poll_function).execute

    future_result = future.value # blocking

    solve(TempResult.new(future_result, (result.retries - 1) , nil))
  end
end