func (r *rttMonitor) reset() {
	r.Lock()
	defer r.Unlock()
	r.averageRTT = 0
	r.averageRTTSet = false
}
reset sets the average RTT to 0. This should only be called from the server monitor when an error occurs during a
server check. Errors in the RTT monitor should not reset the average RTT.
package topology
import (
	"context"
	"sync"
	"time"
	"go.mongodb.org/mongo-driver/x/mongo/driver"
	"go.mongodb.org/mongo-driver/x/mongo/driver/operation"
)
const (
	rttAlphaValue = 0.2
)
type rttConfig struct {
	interval           time.Duration
	createConnectionFn func() (*connection, error)
	createOperationFn  func(driver.Connection) *operation.IsMaster
}
type rttMonitor struct {
	sync.Mutex
	conn          *connection
	averageRTT    time.Duration
	averageRTTSet bool
	closeWg       sync.WaitGroup
	cfg           *rttConfig
	ctx           context.Context
	cancelFn      context.CancelFunc
}
func newRttMonitor(cfg *rttConfig) *rttMonitor {
	ctx, cancel := context.WithCancel(context.Background())
	return &rttMonitor{
		cfg:      cfg,
		ctx:      ctx,
		cancelFn: cancel,
	}
}
func (r *rttMonitor) connect() {
	r.closeWg.Add(1)
	go r.start()
}
func (r *rttMonitor) disconnect() {
	r.cancelFn()
	var conn *connection
	r.Lock()
	conn = r.conn
	r.Unlock()
	if conn != nil {
		conn.closeConnectContext()
		_ = conn.wait()
		_ = conn.close()
	}
	r.closeWg.Wait()
}
func (r *rttMonitor) start() {
	defer r.closeWg.Done()
	ticker := time.NewTicker(r.cfg.interval)
	defer ticker.Stop()
	for {
		if r.ctx.Err() != nil {
			return
		}
		r.pingServer()
		select {
		case <-ticker.C:
		case <-r.ctx.Done():
			return
		}
	}
}