code: func (s *StanServer) replicateSubSentAndAck(sub *subState) {
  	var data []byte
  
  	sr := s.ssarepl
  	sub.Lock()
  	r := sub.replicate
  	if r != nil && len(r.sent)+len(r.ack) > 0 {
  		data = createSubSentAndAckProto(sub, r)
  		r.sent = r.sent[:0]
  		r.ack = r.ack[:0]
  		r.applying = true
  	}
  	sub.Unlock()
  
  	if data != nil {
  		if testSubSentAndAckSlowApply {
  			time.Sleep(100 * time.Millisecond)
  		}
  		s.raft.Apply(data, 0)
  
  		sub.Lock()
  		r = sub.replicate
  		// If r is nil it means either that the leader lost leadrship,
  		// in which case we don't do anything, or the sub/conn is being
  		// closed and endSubSentAndAckReplication() is waiting on a
  		// channel stored in "gates" map. If we find it, signal.
  		if r == nil {
  			if c, ok := sr.gates.Load(sub); ok {
  				sr.gates.Delete(sub)
  				signalCh(c.(chan struct{}))
  			}
  		} else {
  			r.applying = false
  		}
  		sub.Unlock()
  	}
  }
docs: // Replicates through RAFT