ivankelly commented on a change in pull request #2103: Issue 1433: Expose batch 
flushAsync() and flush() methods in Producer
URL: https://github.com/apache/incubator-pulsar/pull/2103#discussion_r200954861
 
 

 ##########
 File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
 ##########
 @@ -1218,7 +1223,22 @@ public void run(Timeout timeout) throws Exception {
     };
 
     @Override
-    protected void flush() {
+    public CompletableFuture<Void> flushAsync() {
+        if (isBatchMessagingEnabled()) {
+            CompletableFuture<MessageId> lastSendFuture;
+            synchronized (ProducerImpl.this) {
+                batchMessageAndSend();
+                lastSendFuture = this.lastSendFuture;
+            }
+            if (null != lastSendFuture) {
+                return lastSendFuture.thenApply(ignored -> null);
+            }
+        }
+        return CompletableFuture.completedFuture(null);
 
 Review comment:
   If you initialize lastSendFuture to CompletableFuture.completedFuture(null), 
you don't need the null check. Also, if batching is not enabled, you should 
still be waiting on lastSendFuture from the previous asyncSend (not sure if 
this is what you're referring to in your comment above).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to