code: func (c *Connection) heartbeater(interval time.Duration, done chan *Error) {
  	const maxServerHeartbeatsInFlight = 3
  
  	var sendTicks <-chan time.Time
  	if interval > 0 {
  		ticker := time.NewTicker(interval)
  		defer ticker.Stop()
  		sendTicks = ticker.C
  	}
  
  	lastSent := time.Now()
  
  	for {
  		select {
  		case at, stillSending := <-c.sends:
  			// When actively sending, depend on sent frames to reset server timer
  			if stillSending {
  				lastSent = at
  			} else {
  				return
  			}
  
  		case at := <-sendTicks:
  			// When idle, fill the space with a heartbeat frame
  			if at.Sub(lastSent) > interval-time.Second {
  				if err := c.send(&heartbeatFrame{}); err != nil {
  					// send heartbeats even after close/closeOk so we
  					// tick until the connection starts erroring
  					return
  				}
  			}
  
  		case conn := <-c.deadlines:
  			// When reading, reset our side of the deadline, if we've negotiated one with
  			// a deadline that covers at least 2 server heartbeats
  			if interval > 0 {
  				conn.SetReadDeadline(time.Now().Add(maxServerHeartbeatsInFlight * interval))
  			}
  
  		case <-done:
  			return
  		}
  	}
  }
docs: // Ensures that at least one frame is being sent at the tuned interval with a
  // jitter tolerance of 1s