55import java .util .concurrent .atomic .AtomicInteger ;
66import software .amazon .lambda .durable .DurableContext ;
77import software .amazon .lambda .durable .DurableHandler ;
8+ import software .amazon .lambda .durable .config .WaitForConditionConfig ;
89import 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