Sha256: 125cf85f9f400c807cab1783b3c72d11cd496c094d2cd4e66293f3429238fe24

Contents?: true

Size: 485 Bytes

Versions: 5

Compression:

Stored size: 485 Bytes

Contents

module Evergreen
  class << self

    ##
    # Provides timeout similar to standard library Timeout, but avoids threads
    #
    def timeout(seconds = 1, error_message = nil, &block)
      start_time = Time.now

      result = nil

      until result
        return result if result = yield

        delay = seconds - (Time.now - start_time)
        if delay <= 0
          raise TimeoutError, error_message || "timed out"
        end

        sleep(0.05)
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
evergreen-1.3.0 lib/evergreen/utils/timeout.rb
evergreen-1.2.0 lib/evergreen/utils/timeout.rb
evergreen-1.1.3 lib/evergreen/utils/timeout.rb
evergreen-1.1.2 lib/evergreen/utils/timeout.rb
evergreen-1.1.0 lib/evergreen/utils/timeout.rb