Sha256: 66f0353c982e36638f0e127bad27b523b3210c030b746133dfa3675064eab355

Contents?: true

Size: 387 Bytes

Versions: 14

Compression:

Stored size: 387 Bytes

Contents

require 'timeout'
module LightIO::Library
  module Timeout
    extend self
    Error = ::Timeout::Error

    def timeout(sec, klass=Error, &blk)
      return yield(sec) if sec.nil? or sec.zero?
      beam = LightIO::Beam.new(sec, &blk)
      message = "execution expired"
      if beam.join(sec).nil?
        raise klass, message
      else
        beam.value
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lightio-0.4.4 lib/lightio/library/timeout.rb
lightio-0.4.3 lib/lightio/library/timeout.rb
lightio-0.4.2 lib/lightio/library/timeout.rb
lightio-0.4.1 lib/lightio/library/timeout.rb
lightio-0.4.0 lib/lightio/library/timeout.rb
lightio-0.4.0.pre lib/lightio/library/timeout.rb
lightio-0.3.2 lib/lightio/library/timeout.rb
lightio-0.3.1 lib/lightio/library/timeout.rb
lightio-0.3.0 lib/lightio/library/timeout.rb
lightio-0.2.2 lib/lightio/library/timeout.rb
lightio-0.2.1 lib/lightio/library/timeout.rb
lightio-0.2.0 lib/lightio/library/timeout.rb
lightio-0.1.1 lib/lightio/library/timeout.rb
lightio-0.1.0 lib/lightio/library/timeout.rb