// Wait() copies the message into a waiting queue, and waits for the corresponding // ack message to be received. func (this *Ackqueue) Wait(msg message.Message, onComplete interface{}) error { this.mu.Lock() defer this.mu.Unlock() switch msg := msg.(type) { case *message.PublishMessage: if msg.QoS() == message.QosAtMostOnce { //return fmt.Errorf("QoS 0 messages don't require ack") return errWaitMessage } this.insert(msg.PacketId(), msg, onComplete) case *message.SubscribeMessage: this.insert(msg.PacketId(), msg, onComplete) case *message.UnsubscribeMessage: this.insert(msg.PacketId(), msg, onComplete) case *message.PingreqMessage: this.ping = ackmsg{ Mtype: message.PINGREQ, State: message.RESERVED, OnComplete: onComplete, } default: return errWaitMessage } return nil }