Skip to content

Commit 81073cc

Browse files
authored
Merge pull request #666 from fjtirado/Fix_#665
[Fix #665] While predicate invoked in proper place
2 parents b23b83b + 5ac65a5 commit 81073cc

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

experimental/lambda/src/main/java/io/serverlessworkflow/impl/executors/func/JavaForExecutorBuilder.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ protected Optional<WorkflowFilter> buildWhileFilter() {
5454
return application
5555
.modelFactory()
5656
.from(
57-
item == null
58-
|| whilePred.test(
59-
n.asJavaObject(),
60-
item,
61-
(Integer) safeObject(t.variables().get(indexName))));
57+
whilePred.test(
58+
n.asJavaObject(),
59+
item,
60+
(Integer) safeObject(t.variables().get(indexName))));
6261
});
6362
}
6463
}

experimental/lambda/src/test/java/io/serverless/workflow/impl/CallTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void testForLoop() throws InterruptedException, ExecutionException {
9696

9797
assertThat(
9898
app.workflowDefinition(workflow)
99-
.instance(List.of(2, 4, 6))
99+
.instance(List.of(2, 4, 6, 7))
100100
.start()
101101
.get()
102102
.asNumber()

impl/core/src/main/java/io/serverlessworkflow/impl/executors/ForExecutor.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,22 @@ protected CompletableFuture<WorkflowModel> internalExecute(
8383
int i = 0;
8484
CompletableFuture<WorkflowModel> future =
8585
CompletableFuture.completedFuture(taskContext.input());
86-
while (iter.hasNext()
87-
&& whileExpr
88-
.map(w -> w.apply(workflow, taskContext, taskContext.rawOutput()))
89-
.map(n -> n.asBoolean().orElse(true))
90-
.orElse(true)) {
86+
while (iter.hasNext()) {
9187
WorkflowModel item = iter.next();
9288
taskContext.variables().put(task.getFor().getEach(), item);
9389
taskContext.variables().put(task.getFor().getAt(), i++);
94-
future =
95-
future.thenCompose(
96-
input ->
97-
TaskExecutorHelper.processTaskList(
98-
taskExecutor, workflow, Optional.of(taskContext), input));
90+
if (whileExpr
91+
.map(w -> w.apply(workflow, taskContext, taskContext.input()))
92+
.map(n -> n.asBoolean().orElse(true))
93+
.orElse(true)) {
94+
future =
95+
future.thenCompose(
96+
input ->
97+
TaskExecutorHelper.processTaskList(
98+
taskExecutor, workflow, Optional.of(taskContext), input));
99+
} else {
100+
break;
101+
}
99102
}
100103
return future;
101104
}

0 commit comments

Comments
 (0)