Skip to content

Commit ade6597

Browse files
committed
update example to use optional config
1 parent 76ec4ff commit ade6597

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

examples/src/main/java/software/amazon/lambda/durable/examples/WaitForConditionExample.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.concurrent.atomic.AtomicInteger;
66
import software.amazon.lambda.durable.DurableContext;
77
import software.amazon.lambda.durable.DurableHandler;
8+
import software.amazon.lambda.durable.config.WaitForConditionConfig;
89
import software.amazon.lambda.durable.model.WaitForConditionResult;
910

1011
/**
@@ -21,17 +22,18 @@ public Integer handleRequest(Integer input, DurableContext context) {
2122
// Poll the shipment status until the order is shipped.
2223
// The check function simulates an order shipment status
2324
// which transitions from PENDING > PROCESSING > SHIPPED
24-
return context.waitForCondition("wait-for-shipment", Integer.class, (callCount, stepCtx) -> {
25-
// Simulate checking shipment status from an external service
26-
if (callCount == null) {
27-
callCount = 0;
28-
}
29-
if (callCount >= 3) {
30-
// Order has shipped — stop polling
31-
return WaitForConditionResult.stopPolling(callCount + 1);
32-
}
33-
// Order still processing — continue polling
34-
return WaitForConditionResult.continuePolling(callCount + 1);
35-
}); // Order pending - initial status
25+
return context.waitForCondition(
26+
"wait-for-shipment",
27+
Integer.class,
28+
(callCount, stepCtx) -> {
29+
// Simulate checking shipment status from an external service
30+
if (callCount >= 3) {
31+
// Order has shipped — stop polling
32+
return WaitForConditionResult.stopPolling(callCount + 1);
33+
}
34+
// Order still processing — continue polling
35+
return WaitForConditionResult.continuePolling(callCount + 1);
36+
},
37+
WaitForConditionConfig.<Integer>builder().initialState(0).build()); // Order pending - initial status
3638
}
3739
}

0 commit comments

Comments
 (0)