code: func (tab *Table) loop() {
  	var (
  		revalidate     = time.NewTimer(tab.nextRevalidateTime())
  		refresh        = time.NewTicker(refreshInterval)
  		copyNodes      = time.NewTicker(copyNodesInterval)
  		refreshDone    = make(chan struct{})           // where doRefresh reports completion
  		revalidateDone chan struct{}                   // where doRevalidate reports completion
  		waiting        = []chan struct{}{tab.initDone} // holds waiting callers while doRefresh runs
  	)
  	defer refresh.Stop()
  	defer revalidate.Stop()
  	defer copyNodes.Stop()
  
  	// Start initial refresh.
  	go tab.doRefresh(refreshDone)
  
  loop:
  	for {
  		select {
  		case <-refresh.C:
  			tab.seedRand()
  			if refreshDone == nil {
  				refreshDone = make(chan struct{})
  				go tab.doRefresh(refreshDone)
  			}
  		case req := <-tab.refreshReq:
  			waiting = append(waiting, req)
  			if refreshDone == nil {
  				refreshDone = make(chan struct{})
  				go tab.doRefresh(refreshDone)
  			}
  		case <-refreshDone:
  			for _, ch := range waiting {
  				close(ch)
  			}
  			waiting, refreshDone = nil, nil
  		case <-revalidate.C:
  			revalidateDone = make(chan struct{})
  			go tab.doRevalidate(revalidateDone)
  		case <-revalidateDone:
  			revalidate.Reset(tab.nextRevalidateTime())
  			revalidateDone = nil
  		case <-copyNodes.C:
  			go tab.copyLiveNodes()
  		case <-tab.closeReq:
  			break loop
  		}
  	}
  
  	if refreshDone != nil {
  		<-refreshDone
  	}
  	for _, ch := range waiting {
  		close(ch)
  	}
  	if revalidateDone != nil {
  		<-revalidateDone
  	}
  	close(tab.closed)
  }
docs: // loop schedules refresh, revalidate runs and coordinates shutdown.