mbien commented on code in PR #7030:
URL: https://github.com/apache/netbeans/pull/7030#discussion_r1480318120


##########
extide/gradle/src/org/netbeans/modules/gradle/execute/GradleDaemonExecutor.java:
##########
@@ -439,41 +441,70 @@ private static String gradleExecutable() {
         return Utilities.isWindows() ? "bin\\gradle.bat" : "bin/gradle"; 
//NOI18N
     }
 
-    public final ExecutorTask createTask(ExecutorTask process) {
+    // TODO one of the two methods can likely go from the API
+    // setTask is called first and signals the runnable to start
+    // the started runnable requires (!) the gradleTask so it can't be created 
in createTask
+    @Override
+    public void setTask(ExecutorTask task) {
         assert gradleTask == null;
-        gradleTask = new GradleTask(process);
+        gradleTask = new GradleTask(task);
+        super.setTask(task);
+    }
+
+    @Override
+    public final ExecutorTask createTask(ExecutorTask process) {
+        assert gradleTask != null;
+        assert task == process;
         return gradleTask;
     }
 
+    // task which can finish early, like a CompletableFuture
     private static final class GradleTask extends ExecutorTask {
-        private final ExecutorTask delegate;
-        private Integer result;
 
+        private final ExecutorTask delegate;
+        private volatile Integer result;
+        // is 0 when wrapper or delegate finished
+        private final CountDownLatch doneSignal = new CountDownLatch(1);
+        
         GradleTask(ExecutorTask delegate) {
             super(() -> {});
             this.delegate = delegate;
+            this.delegate.addTaskListener(t -> doneSignal.countDown());

Review Comment:
   not sure if I understand the question correctly. If someone calls `result()` 
and nothing calls the fast-path `finish(int)` the delegate task will count down 
the latch once it completes and the blocking `result()` method will now unblock 
and return `delegate.result()`.
   
   the second case is that `finish(int)` is called before the delegate task 
completes, this would also unblock all waiting threads which wait on the latch, 
but this time it returns the `result` field without waiting for the delegate 
task.
   
   the second case seems to be the intended purpose of the task wrapper to 
speed up the time-to-result.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to