func (sp *scrapePool) stop() {
	sp.cancel()
	var wg sync.WaitGroup

	sp.mtx.Lock()
	defer sp.mtx.Unlock()

	for fp, l := range sp.loops {
		wg.Add(1)

		go func(l loop) {
			l.stop()
			wg.Done()
		}(l)

		delete(sp.loops, fp)
		delete(sp.activeTargets, fp)
	}
	wg.Wait()
	sp.client.CloseIdleConnections()
}
func (sp *scrapePool) stop() {
	sp.cancel()
	var wg sync.WaitGroup

	sp.mtx.Lock()
	defer sp.mtx.Unlock()

	for fp, l := range sp.loops {
		wg.Add(1)

		go func(l loop) {
			l.stop()
			wg.Done()
		}(l)

		delete(sp.loops, fp)
		delete(sp.activeTargets, fp)
	}
	wg.Wait()
	sp.client.CloseIdleConnections()
}
func ( sp * scrapePool ) stop ( ) { sp . cancel ( ) var wg sync . WaitGroup sp . mtx . Lock ( ) defer sp . mtx . Unlock ( ) for fp , l := range sp . loops { wg . Add ( 1 ) go func ( l loop ) { l . stop ( ) wg . Done ( ) } ( l ) delete ( sp . loops , fp ) delete ( sp . activeTargets , fp ) } wg . Wait ( ) sp . client . CloseIdleConnections ( ) }
// stop terminates all scrape loops and returns after they all terminated.
stop terminates all scrape loops and returns after they all terminated .