Skip to content

Commit 7d47da1

Browse files
committed
Adding until to listen
1 parent 5c91148 commit 7d47da1

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

fluent/agentic/src/test/java/io/serverlessworkflow/fluent/agentic/ChatBotIT.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ void chat_bot() {
7070
t.listen(
7171
"listenToMessages",
7272
l ->
73-
l.one(c -> c.with(event -> event.type("org.acme.chatbot.request"))))
74-
.when(message -> !"".equals(message.get("message")), Map.class)
73+
l.until(message -> !"".equals(message.get("message")), Map.class)
74+
.one(
75+
c ->
76+
c.with(
77+
event -> event.type("org.acme.chatbot.request"))))
7578
.agent(chatBot)
76-
.emit(emit -> emit.event(e -> e.type("org.acme.chatbot.reply")))
77-
.then("listenToMessages"))
79+
.emit(emit -> emit.event(e -> e.type("org.acme.chatbot.reply"))))
7880
.build();
7981

8082
try (WorkflowApplication app = WorkflowApplication.builder().build()) {

fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncListenTaskBuilder.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,37 @@
1515
*/
1616
package io.serverlessworkflow.fluent.func;
1717

18+
import io.serverlessworkflow.api.types.AnyEventConsumptionStrategy;
19+
import io.serverlessworkflow.api.types.ListenTask;
20+
import io.serverlessworkflow.api.types.func.UntilPredicate;
1821
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
1922
import io.serverlessworkflow.fluent.func.spi.FuncTransformations;
2023
import io.serverlessworkflow.fluent.spec.ListenTaskBuilder;
24+
import java.util.function.Predicate;
2125

2226
public class FuncListenTaskBuilder extends ListenTaskBuilder
2327
implements ConditionalTaskBuilder<FuncListenTaskBuilder>,
2428
FuncTransformations<FuncListenTaskBuilder> {
2529

30+
private UntilPredicate untilPredicate;
31+
2632
FuncListenTaskBuilder() {
2733
super();
2834
}
35+
36+
public <T> FuncListenTaskBuilder until(Predicate<T> predicate, Class<T> predClass) {
37+
untilPredicate = new UntilPredicate().withPredicate(predicate, predClass);
38+
return this;
39+
}
40+
41+
@Override
42+
public ListenTask build() {
43+
ListenTask task = super.build();
44+
AnyEventConsumptionStrategy anyEvent =
45+
task.getListen().getTo().getAnyEventConsumptionStrategy();
46+
if (untilPredicate != null && anyEvent != null) {
47+
anyEvent.withUntil(untilPredicate);
48+
}
49+
return task;
50+
}
2951
}

0 commit comments

Comments
 (0)