def with_primary(&block)
      if node = nodes.find(&:primary?)
        begin
          node.ensure_primary do
            return yield(node)
          end
        rescue Errors::ConnectionFailure, Errors::ReplicaSetReconfigured
        end
      end
      raise Errors::ConnectionFailure, "Could not connect to a primary node for replica set #{inspect}"
    end
def with_primary(&block)
      if node = nodes.find(&:primary?)
        begin
          node.ensure_primary do
            return yield(node)
          end
        rescue Errors::ConnectionFailure, Errors::ReplicaSetReconfigured
        end
      end
      raise Errors::ConnectionFailure, "Could not connect to a primary node for replica set #{inspect}"
    end
Yields the replica set's primary node to the provided block. This method
 will retry the block in case of connection errors or replica set
 reconfiguration.

 @example Yield the primary to the block.
   cluster.with_primary do |node|
     # ...
   end

 @param [ Integer ] retries The number of times to retry.

 @raises [ ConnectionFailure ] When no primary node can be found

 @return [ Object ] The result of the yield.

 @since 1.0.0