Sha256: 65714ca2e3b23e54afc57c5f5070a60a6517c3d4160e4096786c6c0e449f2749

Contents?: true

Size: 607 Bytes

Versions: 8

Compression:

Stored size: 607 Bytes

Contents

module HandlesTimeout
  def self.included(base)
    base.extend ClassMethods
  end

  RequestTimeout = Class.new

  module ClassMethods
    def handle_timeout(method_name)
      alias_method "#{method_name}_without_timeout", method_name
      define_method method_name do |*args|
        begin
          if args.empty?
            Timeout::timeout(5) { send("#{method_name}_without_timeout") }
          else
            Timeout::timeout(5) { send("#{method_name}_without_timeout", *args) }
          end
        rescue Timeout::Error
          [nil, RequestTimeout]
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
keikokuc-0.8 lib/handles_timeout.rb
keikokuc-0.7 lib/handles_timeout.rb
keikokuc-0.6 lib/handles_timeout.rb
keikokuc-0.5 lib/handles_timeout.rb
keikokuc-0.4 lib/handles_timeout.rb
keikokuc-0.3 lib/handles_timeout.rb
keikokuc-0.2 lib/handles_timeout.rb
keikokuc-0.1 lib/handles_timeout.rb