Class: MethodDecorators::Within

Inherits:
Decorator show all
Defined in:
lib/method_decorators/within.rb

Instance Method Summary collapse

Methods inherited from Decorator

#+@, +@, current_decorators

Constructor Details

#initialize(timeout, exception_class = nil) ⇒ Within

Returns a new instance of Within.



6
7
8
9
# File 'lib/method_decorators/within.rb', line 6

def initialize(timeout, exception_class = nil)
  @seconds = timeout
  @exception_class = exception_class
end

Instance Method Details

#call(orig, this, *args, &blk) ⇒ Object



11
12
13
14
15
# File 'lib/method_decorators/within.rb', line 11

def call(orig, this, *args, &blk)
  Timeout.timeout(@seconds, @exception_class) do
    orig.call(*args, &blk)
  end
end