Module: Concurrent::Polling

Defined in:
lib/concurrent/polling.rb,
lib/concurrent/polling/version.rb

Defined Under Namespace

Classes: FinalResult, Solver, TempResult

Constant Summary collapse

DEFAULT_OPTIONS =
{
  retries: 1,
  success_condition: lambda {|polled_value| true },
  poll: lambda { :default_options_polling_result }
}
TimeoutError =
Class.new(StandardError)
ConditionError =
Class.new(StandardError)
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.poll(options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/concurrent/polling.rb', line 51

def self.poll(options = {})

  opts = DEFAULT_OPTIONS.merge(options)

  success_condition = opts[:success_condition]
  poll = opts[:poll]


  retries = opts[:retries]

  solver = Solver.new(poll, success_condition )
  promise = Promise.new{ solver.solve(TempResult.new(poll.call(), retries, nil)) }
    .rescue { |reason| FinalResult.with(ok: nil, reason: reason)}
    .then { |result| FinalResult.new(result.ok, result.reason) }

  promise.execute
  promise.value
end