package mtproto

import (
	

	
	

	
)

func ( *Conn) ( context.Context) error {
	 := .log.Named("ack")

	var  []int64
	 := func() {
		defer func() {  = [:0] }()

		 := .clock.Now()
		if  := .writeServiceMessage(, &mt.MsgsAck{MsgIDs: });  != nil {
			// A failing ack write is a strong signal that the outgoing half of
			// the connection is broken while the read loop still works.
			.log.Error(, "Failed to ACK", log.Error(), log.Any("msg_ids", ))
			return
		}

		.Debug(, "Ack",
			log.Any("msg_ids", ),
			log.Duration("elapsed", .clock.Now().Sub()),
		)
	}

	 := .clock.Ticker(.ackInterval)
	defer .Stop()

	for {
		select {
		case <-.Done():
			return errors.Wrap(.Err(), "acl")
		case <-.C():
			if len() > 0 {
				()
			}
		case  := <-.ackSendChan:
			 = append(, )
			if len() >= .ackBatchSize {
				()
				.Reset(.ackInterval)
			}
		}
	}
}