def each(&block)
      r = true
      while r
        r = next_record
        # nil means EOF
        unless r.nil?
          block.call(r)
        else
          # reached the EOF
          break
        end
      end
    end
def each(&block)
      r = true
      while r
        r = next_record
        # nil means EOF
        unless r.nil?
          block.call(r)
        else
          # reached the EOF
          break
        end
      end
    end
fetches and returns all the records from the queue until the whole operation is finished and it reaches an EOF mark
 calling cancel inside the each block raises an exception to signal other consumer threads