Sha256: bece00b3fc564d5acf25d0761414f19f1386d7771accff43d0cf9d93a7dd68c5

Contents?: true

Size: 558 Bytes

Versions: 1

Compression:

Stored size: 558 Bytes

Contents

#
# The waiter waits.
#
module Waiter
  require 'timeout'

  POLL_SLEEP_TIME = 0.01
  DEFAULT_TIMEOUT = 5

  # The lambda passed to await should return false if thing not found
  # and something truthy if found
  def await(lamb, timeout = DEFAULT_TIMEOUT, poll_sleep_time = POLL_SLEEP_TIME)
    Timeout.timeout(timeout) do
      loop do
        result = lamb.call
        return result if result
        # rubocop:disable Style/SleepCop
        sleep poll_sleep_time
        # rubocop:enable Style/SleepCop
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rutl-0.8.0 lib/utilities/waiter.rb