Class: Dry::Effects::Providers::Timeout
- Inherits:
-
Object
- Object
- Dry::Effects::Providers::Timeout
- Defined in:
- lib/dry/effects/providers/timeout.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#call(timeout) ⇒ Object
private
Yield the block with the handler installed.
- #provide?(effect) ⇒ Boolean
- #read_clock ⇒ Object
- #timeout ⇒ Object
Class Method Details
.handle_method(_scope, as: Undefined) ⇒ Object
7 8 9 |
# File 'lib/dry/effects/providers/timeout.rb', line 7 def self.handle_method(_scope, as: Undefined, **) Undefined.default(as) { :with_timeout } end |
Instance Method Details
#call(timeout) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Yield the block with the handler installed
26 27 28 29 30 |
# File 'lib/dry/effects/providers/timeout.rb', line 26 def call(timeout) @time_out_at = read_clock + timeout yield end |
#provide?(effect) ⇒ Boolean
35 36 37 |
# File 'lib/dry/effects/providers/timeout.rb', line 35 def provide?(effect) effect.type.equal?(:timeout) && scope.equal?(effect.scope) end |
#read_clock ⇒ Object
39 40 41 |
# File 'lib/dry/effects/providers/timeout.rb', line 39 def read_clock ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) end |
#timeout ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/dry/effects/providers/timeout.rb', line 13 def timeout left = @time_out_at - read_clock if left <= 0 0.0 else left end end |