code: func (s *Subscription) processNextMsgDelivered(msg *Msg) error {
  	s.mu.Lock()
  	nc := s.conn
  	max := s.max
  
  	// Update some stats.
  	s.delivered++
  	delivered := s.delivered
  	if s.typ == SyncSubscription {
  		s.pMsgs--
  		s.pBytes -= len(msg.Data)
  	}
  	s.mu.Unlock()
  
  	if max > 0 {
  		if delivered > max {
  			return ErrMaxMessages
  		}
  		// Remove subscription if we have reached max.
  		if delivered == max {
  			nc.mu.Lock()
  			nc.removeSub(s)
  			nc.mu.Unlock()
  		}
  	}
  
  	return nil
  }
docs: // processNextMsgDelivered takes a message and applies the needed
  // accounting to the stats from the subscription, returning an
  // error in case we have the maximum number of messages have been
  // delivered already. It should not be called while holding the lock.