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