Sha256: c77cc9f902e975d317b5ed96676a9a0fb8cc2698e6dec48804597665d7a6c5f8

Contents?: true

Size: 474 Bytes

Versions: 3

Compression:

Stored size: 474 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
          Timeout::timeout(5) { send("#{method_name}_without_timeout", args) }
        rescue Timeout::Error
          [nil, RequestTimeout]
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
keikokuc-0.0.3 lib/handles_timeout.rb
keikokuc-0.0.2 lib/handles_timeout.rb
keikokuc-0.0.1 lib/handles_timeout.rb