@@ -564,21 +564,23 @@ void BufferedProducer<BufferType, Allocator>::flush(bool preserve_order) {
564
564
565
565
template <typename BufferType, typename Allocator>
566
566
bool BufferedProducer<BufferType, Allocator>::flush(std::chrono::milliseconds timeout,
567
- bool preserve_order) {
567
+ bool preserve_order) {
568
568
if (preserve_order) {
569
569
CounterGuard<size_t > counter_guard (flushes_in_progress_);
570
570
QueueType flush_queue; // flush from temporary queue
571
571
{
572
572
std::lock_guard<std::mutex> lock (mutex_);
573
573
std::swap (messages_, flush_queue);
574
574
}
575
+ auto remaining = timeout;
575
576
auto start_time = std::chrono::high_resolution_clock::now ();
576
- while (!flush_queue.empty () &&
577
- (std::chrono::duration_cast<std::chrono::milliseconds>
578
- (std::chrono::high_resolution_clock::now () - start_time) < timeout)) {
577
+ do {
579
578
sync_produce (flush_queue.front ());
580
579
flush_queue.pop_front ();
581
- }
580
+ // calculate remaining time
581
+ remaining = timeout - std::chrono::duration_cast<std::chrono::milliseconds>
582
+ (std::chrono::high_resolution_clock::now () - start_time);
583
+ } while (!flush_queue.empty () && (remaining.count () > 0 ));
582
584
}
583
585
else {
584
586
async_flush ();
@@ -608,7 +610,7 @@ template <typename BufferType, typename Allocator>
608
610
bool BufferedProducer<BufferType, Allocator>::wait_for_acks(std::chrono::milliseconds timeout) {
609
611
auto remaining = timeout;
610
612
auto start_time = std::chrono::high_resolution_clock::now ();
611
- while ((pending_acks_ > 0 ) && (remaining. count () > 0 )) {
613
+ do {
612
614
try {
613
615
producer_.flush (remaining);
614
616
}
@@ -625,7 +627,7 @@ bool BufferedProducer<BufferType, Allocator>::wait_for_acks(std::chrono::millise
625
627
// calculate remaining time
626
628
remaining = timeout - std::chrono::duration_cast<std::chrono::milliseconds>
627
629
(std::chrono::high_resolution_clock::now () - start_time);
628
- }
630
+ } while ((pending_acks_ > 0 ) && (remaining. count () > 0 ));
629
631
return (pending_acks_ == 0 );
630
632
}
631
633
0 commit comments