Skip to content

Commit 9159c3f

Browse files
committed
add CF supplyAsync
1 parent 4774a20 commit 9159c3f

File tree

1 file changed

+15
-0
lines changed
  • src/main/java/org/dataloader/orchestration

1 file changed

+15
-0
lines changed

src/main/java/org/dataloader/orchestration/CF.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.concurrent.LinkedBlockingDeque;
66
import java.util.concurrent.atomic.AtomicReference;
77
import java.util.function.BiFunction;
8+
import java.util.function.Supplier;
89

910
public class CF<T> {
1011

@@ -71,6 +72,20 @@ public static <T> CF<T> newExceptionally(Throwable e) {
7172
return result;
7273
}
7374

75+
public static <T> CF<T> supplyAsync(Supplier<T> supplier,
76+
Executor executor) {
77+
78+
CF<T> result = new CF<>();
79+
executor.execute(() -> {
80+
try {
81+
result.encodeAndSetResult(supplier.get());
82+
} catch (Throwable ex) {
83+
result.encodeAndSetResult(ex);
84+
}
85+
});
86+
return result;
87+
}
88+
7489

7590
public <U> CF<U> map(BiFunction<? super T, Throwable, ? extends U> fn) {
7691
CF<U> newResult = new CF<>();

0 commit comments

Comments
 (0)