Sha256: 5c309d139566aef6ed51d37e76b11a00ca181bff7cdfd73929deb27ba519af43

Contents?: true

Size: 576 Bytes

Versions: 2

Compression:

Stored size: 576 Bytes

Contents

module Terminus
  module Timeouts

    class TimeoutError < StandardError
    end

    include Faye::Timeouts
    TIMEOUT = 30

    def wait_with_timeout(name, duration = TIMEOUT, &predicate)
      result, time_out = predicate.call, false
      return result if result

      add_timeout(name, duration) { time_out = true }

      while !result and !time_out
        result = predicate.call
        sleep(0.001)
      end

      raise TimeoutError.new("Waited #{duration}s but could not get a #{name}") if time_out
      remove_timeout(name)

      result
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
terminus-0.6.0 lib/terminus/timeouts.rb
terminus-0.5.0 lib/terminus/timeouts.rb