class Dry::Effects::Providers::Timeout

Public Class Methods

handle_method(_scope, as: Undefined, **) click to toggle source
# File lib/dry/effects/providers/timeout.rb, line 9
def self.handle_method(_scope, as: Undefined, **)
  Undefined.default(as) { :with_timeout }
end

Public Instance Methods

call(timeout) { || ... } click to toggle source

Yield the block with the handler installed

@api private

# File lib/dry/effects/providers/timeout.rb, line 28
def call(timeout)
  @time_out_at = read_clock + timeout

  yield
end
provide?(effect) click to toggle source

@param [Effect] effect @return [Boolean] @api public

# File lib/dry/effects/providers/timeout.rb, line 37
def provide?(effect)
  effect.type.equal?(:timeout) && scope.equal?(effect.scope)
end
read_clock() click to toggle source
# File lib/dry/effects/providers/timeout.rb, line 41
def read_clock
  ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
end
timeout() click to toggle source
# File lib/dry/effects/providers/timeout.rb, line 15
def timeout
  left = @time_out_at - read_clock

  if left <= 0
    0.0
  else
    left
  end
end