Sha256: 542b70ae6a1519a536335ba3169aaa7d4f7e7e312dc5973923bbdef8b76bcb3e

Contents?: true

Size: 1002 Bytes

Versions: 2

Compression:

Stored size: 1002 Bytes

Contents

module LIFX
  # @private
  module Utilities
    def try_until(condition_proc, timeout_exception: TimeoutError,
                                            timeout: 3,
                                 condition_interval: 0.1,
                                    action_interval: 0.5,
                                             signal: nil, &action_block)
      Timeout.timeout(timeout) do
        m = Mutex.new
        time = 0
        while !condition_proc.call
          if Time.now.to_f - time > action_interval
            time = Time.now.to_f
            action_block.call
          end
          if signal
            m.synchronize do
              signal.wait(m, condition_interval)
            end
          else
            sleep(condition_interval)
          end
        end
      end
    rescue Timeout::Error
      raise timeout_exception if timeout_exception
    end

    def tag_ids_from_field(tags_field)
      (0...64).to_a.select { |t| (tags_field & (2 ** t)) > 0 }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lifx-0.4.11 lib/lifx/utilities.rb
lifx-0.4.10 lib/lifx/utilities.rb