@@ -144,8 +144,7 @@ func (d *deferredConfirmations) Confirm(confirmation Confirmation) {
144144 // we should never receive a confirmation for a tag that hasn't been published, but a test causes this to happen
145145 return
146146 }
147- dc .confirmation = confirmation
148- dc .cancel ()
147+ dc .Confirm (confirmation .Ack )
149148 delete (d .confirmations , confirmation .DeliveryTag )
150149}
151150
@@ -155,8 +154,7 @@ func (d *deferredConfirmations) ConfirmMultiple(confirmation Confirmation) {
155154
156155 for k , v := range d .confirmations {
157156 if k <= confirmation .DeliveryTag {
158- v .confirmation = Confirmation {DeliveryTag : k , Ack : confirmation .Ack }
159- v .cancel ()
157+ v .Confirm (confirmation .Ack )
160158 delete (d .confirmations , k )
161159 }
162160 }
@@ -168,14 +166,25 @@ func (d *deferredConfirmations) Close() {
168166 defer d .m .Unlock ()
169167
170168 for k , v := range d .confirmations {
171- v .confirmation = Confirmation {DeliveryTag : k , Ack : false }
172- v .cancel ()
169+ v .Confirm (false )
173170 delete (d .confirmations , k )
174171 }
175172}
176173
174+ // Confirm ack confirmation.
175+ func (d * DeferredConfirmation ) Confirm (ack bool ) {
176+ d .m .Lock ()
177+ defer d .m .Unlock ()
178+
179+ d .confirmation .Ack = ack
180+ d .cancel ()
181+ }
182+
177183// Waits for publisher confirmation. Returns true if server successfully received the publishing.
178184func (d * DeferredConfirmation ) Wait () bool {
179185 <- d .ctx .Done ()
186+
187+ d .m .Lock ()
188+ defer d .m .Unlock ()
180189 return d .confirmation .Ack
181190}
0 commit comments