From c8742b10f019cbd093e8c6873ddd00759ff0b511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Mendoza=20P=C3=A9rez?= Date: Tue, 30 Apr 2024 08:13:19 +0200 Subject: [PATCH] fix commented code --- build.gradle | 2 +- .../asyncchild/ParentWorkflowImpl.java | 47 +++++++------------ 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/build.gradle b/build.gradle index c5fa37af..a31abc5a 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ subprojects { apply plugin: 'com.diffplug.spotless' compileJava { -// options.compilerArgs << "-Werror" + options.compilerArgs << "-Werror" } java { diff --git a/core/src/main/java/io/temporal/samples/asyncchild/ParentWorkflowImpl.java b/core/src/main/java/io/temporal/samples/asyncchild/ParentWorkflowImpl.java index cabd79f9..61dd13b3 100644 --- a/core/src/main/java/io/temporal/samples/asyncchild/ParentWorkflowImpl.java +++ b/core/src/main/java/io/temporal/samples/asyncchild/ParentWorkflowImpl.java @@ -25,40 +25,27 @@ import io.temporal.workflow.ChildWorkflowOptions; import io.temporal.workflow.Promise; import io.temporal.workflow.Workflow; -import java.util.ArrayList; -import java.util.List; public class ParentWorkflowImpl implements ParentWorkflow { @Override public WorkflowExecution executeParent() { - final List> promises = new ArrayList<>(); - - for (int i = 0; i < 1000; i++) { - // We set the parentClosePolicy to "Abandon" - // This will allow child workflow to continue execution after parent completes - ChildWorkflowOptions childWorkflowOptions = - ChildWorkflowOptions.newBuilder() - .setWorkflowId("childWorkflow" + Math.random()) - .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON) - .build(); - - // Get the child workflow stub - ChildWorkflow child = - Workflow.newChildWorkflowStub(ChildWorkflow.class, childWorkflowOptions); - // Start the child workflow async - Async.function(child::executeChild); - // Get the child workflow execution promise - Promise childExecution = Workflow.getWorkflowExecution(child); - // Call .get on the promise. This will block until the child workflow starts execution (or - // start - // fails) - - promises.add(childExecution); - } - - Promise.allOf(promises).get(); - - return promises.get(0).get(); + // We set the parentClosePolicy to "Abandon" + // This will allow child workflow to continue execution after parent completes + ChildWorkflowOptions childWorkflowOptions = + ChildWorkflowOptions.newBuilder() + .setWorkflowId("childWorkflow") + .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON) + .build(); + + // Get the child workflow stub + ChildWorkflow child = Workflow.newChildWorkflowStub(ChildWorkflow.class, childWorkflowOptions); + // Start the child workflow async + Async.function(child::executeChild); + // Get the child workflow execution promise + Promise childExecution = Workflow.getWorkflowExecution(child); + // Call .get on the promise. This will block until the child workflow starts execution (or start + // fails) + return childExecution.get(); } }