Class: Dry::Effects::Providers::Timeout

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/effects/providers/timeout.rb

Class Method Summary collapse

Instance Method Summary collapse

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

API:

  • private



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

Parameters:

Returns:

API:

  • public



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_clockObject



39
# File 'lib/dry/effects/providers/timeout.rb', line 39

def read_clock = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)

#timeoutObject



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