code: func (d *requestDistributor) loop() {
  	for {
  		select {
  		case <-d.stopChn:
  			d.lock.Lock()
  			elem := d.reqQueue.Front()
  			for elem != nil {
  				req := elem.Value.(*distReq)
  				close(req.sentChn)
  				req.sentChn = nil
  				elem = elem.Next()
  			}
  			d.lock.Unlock()
  			return
  		case <-d.loopChn:
  			d.lock.Lock()
  			d.loopNextSent = false
  		loop:
  			for {
  				peer, req, wait := d.nextRequest()
  				if req != nil && wait == 0 {
  					chn := req.sentChn // save sentChn because remove sets it to nil
  					d.remove(req)
  					send := req.request(peer)
  					if send != nil {
  						peer.queueSend(send)
  					}
  					chn <- peer
  					close(chn)
  				} else {
  					if wait == 0 {
  						// no request to send and nothing to wait for; the next
  						// queued request will wake up the loop
  						break loop
  					}
  					d.loopNextSent = true // a "next" signal has been sent, do not send another one until this one has been received
  					if wait > distMaxWait {
  						// waiting times may be reduced by incoming request replies, if it is too long, recalculate it periodically
  						wait = distMaxWait
  					}
  					go func() {
  						d.clock.Sleep(wait)
  						d.loopChn <- struct{}{}
  					}()
  					break loop
  				}
  			}
  			d.lock.Unlock()
  		}
  	}
  }
docs: // main event loop