33package com .amazonaws .lambda .durable ;
44
55import com .amazonaws .lambda .durable .operation .DurableOperation ;
6+ import java .util .Arrays ;
7+ import java .util .List ;
68
79public class DurableFuture <T > {
810 private final DurableOperation <T > operation ;
@@ -22,4 +24,33 @@ public DurableFuture(DurableOperation<T> operation) {
2224 public T get () {
2325 return operation .get ();
2426 }
27+
28+ /**
29+ * Waits for all provided futures to complete and returns their results in order.
30+ *
31+ * <p>The futures are resolved sequentially, but since the underlying operations run concurrently, this effectively
32+ * waits for all operations to complete. During replay, completed operations return immediately.
33+ *
34+ * @param futures the futures to wait for
35+ * @param <T> the result type of the futures
36+ * @return a list of results in the same order as the input futures
37+ */
38+ @ SafeVarargs
39+ public static <T > List <T > allOf (DurableFuture <T >... futures ) {
40+ return Arrays .stream (futures ).map (DurableFuture ::get ).toList ();
41+ }
42+
43+ /**
44+ * Waits for all provided futures to complete and returns their results in order.
45+ *
46+ * <p>The futures are resolved sequentially, but since the underlying operations run concurrently, this effectively
47+ * waits for all operations to complete. During replay, completed operations return immediately.
48+ *
49+ * @param futures the list of futures to wait for
50+ * @param <T> the result type of the futures
51+ * @return a list of results in the same order as the input futures
52+ */
53+ public static <T > List <T > allOf (List <DurableFuture <T >> futures ) {
54+ return futures .stream ().map (DurableFuture ::get ).toList ();
55+ }
2556}
0 commit comments