File tree Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 68
68
69
69
then-compose then-compose-async
70
70
71
- then-handle then-handle-async )
71
+ then-handle then-handle-async
72
+ then-exceptionally )
72
73
73
74
; ; The potemkin abstract type for
74
75
; ; implementations such as CompletionStage
149
150
(handleAsync [this operator]
150
151
(then-handle-async this operator))
151
152
(handleAsync [this operator executor]
152
- (then-handle-async this operator executor)))
153
+ (then-handle-async this operator executor))
154
+
155
+ (exceptionally [this operator]
156
+ (then-exceptionally this operator)))
153
157
154
158
(definline realized?
155
159
" Returns true if the manifold deferred is realized."
1617
1621
(def ^:private then-handle-async (async-for then-handle))
1618
1622
1619
1623
1620
-
1624
+ (defn- then-exceptionally [this ^java.util.function.Function operator]
1625
+ (assert-some operator)
1626
+ (catch this #(.apply operator %)))
1621
1627
1622
1628
; ;;
1623
1629
Original file line number Diff line number Diff line change 420
420
(let [ex (RuntimeException. )
421
421
d1 ^CompletionStage (d/error-deferred ex)
422
422
d2 (.handleAsync d1 (fn->BiFunction
423
- (fn [x error]
423
+ (fn [x ^Throwable error]
424
424
(is (nil? x))
425
- (is (#{ex (.getCause ex )} error ))
425
+ (is (#{error (.getCause error )} ex ))
426
426
2
427
427
)))]
428
428
429
429
(is (thrown? RuntimeException @d1))
430
430
(is (= 2 @d2)))))
431
+
432
+ (deftest test-exceptionally
433
+ (testing " .exceptionally success"
434
+ (let [d1 ^CompletionStage (d/success-deferred 1 )
435
+ d2 (.exceptionally
436
+ d1
437
+ (fn->Function
438
+ (fn [_]
439
+ (throw (RuntimeException.
440
+ " This should not run" )))))]
441
+
442
+ (is (= 1 @d1))
443
+ (is (= 1 @d2))))
444
+
445
+ (testing " .exceptionally failure"
446
+ (let [base-error (RuntimeException. )
447
+ d1 ^CompletionStage (d/error-deferred base-error)
448
+ d2 (.exceptionally
449
+ d1
450
+ (fn->Function
451
+ (fn [^Throwable error]
452
+ (is (#{error (.getCause error)} base-error))
453
+ 2 )))]
454
+
455
+ (is (thrown? RuntimeException @d1))
456
+ (is (= 2 @d2)))))
You can’t perform that action at this time.
0 commit comments