File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 69
69
then-compose then-compose-async
70
70
71
71
then-handle then-handle-async
72
- then-exceptionally )
72
+ then-exceptionally
73
+
74
+ to-completable-future )
73
75
74
76
; ; The potemkin abstract type for
75
77
; ; implementations such as CompletionStage
153
155
(then-handle-async this operator executor))
154
156
155
157
(exceptionally [this operator]
156
- (then-exceptionally this operator)))
158
+ (then-exceptionally this operator))
159
+
160
+ (toCompletableFuture [this]
161
+ (to-completable-future this)))
157
162
158
163
(definline realized?
159
164
" Returns true if the manifold deferred is realized."
1625
1630
(assert-some operator)
1626
1631
(catch this #(.apply operator %)))
1627
1632
1633
+ (defn- to-completable-future [this]
1634
+
1635
+ (let [result (java.util.concurrent.CompletableFuture. )]
1636
+
1637
+ (on-realized this
1638
+ #(.complete result %)
1639
+ #(.completeExceptionally result %))
1640
+
1641
+ result
1642
+ ))
1643
+
1628
1644
; ;;
1629
1645
1630
1646
(alter-meta! #'->Deferred assoc :private true )
Original file line number Diff line number Diff line change 454
454
455
455
(is (thrown? RuntimeException @d1))
456
456
(is (= 2 @d2)))))
457
+
458
+ (deftest test-to-completable-future
459
+ (testing " .toCompletableFuture success"
460
+ (let [base ^CompletionStage (d/deferred )
461
+ target ^CompletableFuture (.toCompletableFuture base)]
462
+
463
+ (is (not (.isDone target)))
464
+
465
+ (d/success! base 10 )
466
+
467
+ (is (.isDone target))
468
+
469
+ (is (= 10 (.get target)))))
470
+
471
+ (testing " .toCompletableFuture error"
472
+ (let [base ^CompletionStage (d/deferred )
473
+ target ^CompletableFuture (.toCompletableFuture base)]
474
+
475
+ (is (not (.isDone target)))
476
+
477
+ (d/error! base (RuntimeException. ))
478
+
479
+ (is (.isDone target))
480
+
481
+ (is (thrown? RuntimeException (.getNow target nil ))))))
You can’t perform that action at this time.
0 commit comments