You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/09/13 01:58:06 UTC

[GitHub] carryxyh closed pull request #2495: Tempfuture

carryxyh closed pull request #2495: Tempfuture
URL: https://github.com/apache/incubator-dubbo/pull/2495
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
index 0ae9867dd0..971a9ad079 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
@@ -39,6 +39,11 @@
 
     protected CompletableFuture<Result> resultFuture;
 
+    /**
+     * relate valueFuture and resultFuture
+     */
+    protected CompletableFuture<Object> tempFuture;
+
     public AsyncRpcResult(CompletableFuture<Object> future) {
         this(future, true);
     }
@@ -58,12 +63,11 @@ public AsyncRpcResult(CompletableFuture<Object> future, final CompletableFuture<
         }
         resultFuture = rFuture;
         if (registerCallback) {
-            /**
-             * We do not know whether future already completed or not, it's a future exposed or even created by end user.
-             * 1. future complete before whenComplete. whenComplete fn (resultFuture.complete) will be executed in thread subscribing, in our case, it's Dubbo thread.
-             * 2. future complete after whenComplete. whenComplete fn (resultFuture.complete) will be executed in thread calling complete, normally its User thread.
-             */
-            future.whenComplete((v, t) -> {
+            // tempFuture only init if register call back
+            tempFuture = new CompletableFuture<>();
+
+            // tempFuture trigger resultFuture
+            tempFuture.whenComplete((v, t) -> {
                 RpcResult rpcResult;
                 if (t != null) {
                     if (t instanceof CompletionException) {
@@ -74,9 +78,11 @@ public AsyncRpcResult(CompletableFuture<Object> future, final CompletableFuture<
                 } else {
                     rpcResult = new RpcResult(v);
                 }
-                // instead of resultFuture we must use rFuture here, resultFuture may being changed before complete when building filter chain, but rFuture was guaranteed never changed by closure.
-                rFuture.complete(rpcResult);
+                resultFuture.complete(rpcResult);
             });
+
+            // valueFuture trigger tempFuture
+            future.whenComplete((v, t) -> tempFuture.complete(v));
         }
         this.valueFuture = future;
         this.storedContext = RpcContext.getContext();


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org