Sha256: 6d4ba0b882de779d33863932b3f0aaa11fa2dd7613226ec24a6e515d2f280da6

Contents?: true

Size: 567 Bytes

Versions: 1

Compression:

Stored size: 567 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 = nil, false
      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

1 entries across 1 versions & 1 rubygems

Version Path
terminus-0.3.0 lib/terminus/timeouts.rb