You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: wait_for_helper.rb
    path of file: ./repos/appsignal-ruby/spec/support/helpers
    
    the code of the file until where you have to start completion: module WaitForHelper
  # Wait for a condition to be met
  #
  # @example
  #   # Perform threaded opera
    
  def wait_for(name)
    max_wait = 5_000
    i = 0
    error = nil
    while i < max_wait
      begin
        result = yield
        break if result
      rescue Exception => e # rubocop:disable Lint/RescueException
        # Capture error so we know if it exited with an error
        error = e
      ensure
        i += 1
        sleep 0.001
      end