Class: Reacto::Operations::RetryWhen
- Inherits:
-
Object
- Object
- Reacto::Operations::RetryWhen
- Defined in:
- lib/reacto/operations/retry_when.rb
Instance Method Summary collapse
- #call(tracker) ⇒ Object
-
#initialize(behaviour, predicate) ⇒ RetryWhen
constructor
A new instance of RetryWhen.
Constructor Details
#initialize(behaviour, predicate) ⇒ RetryWhen
Returns a new instance of RetryWhen.
6 7 8 9 10 |
# File 'lib/reacto/operations/retry_when.rb', line 6 def initialize(behaviour, predicate) @behaviour = behaviour @predicate = predicate @retries = {} end |
Instance Method Details
#call(tracker) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/reacto/operations/retry_when.rb', line 12 def call(tracker) @retries[tracker] ||= 0 error = -> (e) do should_retry = @predicate.call(e, @retries[tracker]) if should_retry @retries[tracker] += 1 @behaviour.call(self.call(tracker)) else tracker.on_error(e) end end Subscriptions::OperationSubscription.new(tracker, error: error) end |