Sha256: dd4d1e92b4f0eec9179977b3cb14ce40607a8dbc3118dafc287be61bbd9aab75

Contents?: true

Size: 719 Bytes

Versions: 21

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true

require 'timeout'

# Timeout extensions
module ::Timeout

  # Sets a timeout for the given block. This method provides an equivalent API
  # to the stock Timeout API provided by Ruby. In case of a timeout, the block
  # will be interrupted and an exception will be raised according to the given
  # arguments.
  #
  # @param sec [Number] timeout period in seconds
  # @param klass [Class] exception class
  # @param message [String] exception message
  # @param &block [Proc] code to run
  # @return [any] block's return value
  def self.timeout(sec, klass = Timeout::Error, message = 'execution expired', &block)
    cancel_after(sec, with_exception: [klass, message], &block)
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
polyphony-0.99 lib/polyphony/extensions/timeout.rb
polyphony-0.98 lib/polyphony/extensions/timeout.rb
polyphony-0.97 lib/polyphony/extensions/timeout.rb
polyphony-0.96 lib/polyphony/extensions/timeout.rb
polyphony-0.95 lib/polyphony/extensions/timeout.rb
polyphony-0.94 lib/polyphony/extensions/timeout.rb
polyphony-0.93 lib/polyphony/extensions/timeout.rb
polyphony-0.92 lib/polyphony/extensions/timeout.rb
polyphony-0.91 lib/polyphony/extensions/timeout.rb
polyphony-0.90 lib/polyphony/extensions/timeout.rb
polyphony-0.89 lib/polyphony/extensions/timeout.rb
polyphony-0.87 lib/polyphony/extensions/timeout.rb
polyphony-0.86 lib/polyphony/extensions/timeout.rb
polyphony-0.85 lib/polyphony/extensions/timeout.rb
polyphony-0.84.1 lib/polyphony/extensions/timeout.rb
polyphony-0.84 lib/polyphony/extensions/timeout.rb
polyphony-0.83 lib/polyphony/extensions/timeout.rb
polyphony-0.82 lib/polyphony/extensions/timeout.rb
polyphony-0.81.1 lib/polyphony/extensions/timeout.rb
polyphony-0.81 lib/polyphony/extensions/timeout.rb