File tree Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Original file line number Diff line number Diff line change 1649
1649
1650
1650
result))
1651
1651
1652
- (defn- when-complete [this ^java.util.function.BiConsumer operator]
1653
- (assert-some operator)
1654
- (on-realized this
1655
- #(.accept operator % nil )
1656
- #(.accept operator nil %))
1657
- this )
1652
+ (defn- when-complete [d ^BiConsumer f]
1653
+ (assert-some f)
1654
+ (let [d' (deferred )]
1655
+ (on-realized d
1656
+ (fn [val]
1657
+ (try (.accept f val nil )
1658
+ (success! d' val)
1659
+ (catch Throwable err
1660
+ (error! d' err))))
1661
+ (fn [err]
1662
+ (try (.accept f nil err)
1663
+ (error! d' err)
1664
+ (catch Throwable _
1665
+ (error! d' err)))))
1666
+ d'))
1658
1667
1659
1668
(def ^:private when-complete-async (async-for when-complete ))
1660
1669
Original file line number Diff line number Diff line change 524
524
525
525
(is (thrown? RuntimeException @d1))
526
526
(is (thrown? RuntimeException @d2))
527
- (is (= true @was-called))))
527
+ (is (= true @was-called)))
528
+
529
+ (let [d1 (d/success-deferred 1 )
530
+ d2 (method
531
+ d1
532
+ (fn->BiConsumer (fn [_ _] (throw (RuntimeException. ))))
533
+ executor)]
534
+
535
+ (is (thrown? RuntimeException @d2)))
536
+
537
+ (let [error (RuntimeException. " d1 error" )
538
+ d1 (d/error-deferred error)
539
+ d2 (method
540
+ d1
541
+ (fn->BiConsumer (fn [_ _]
542
+ (throw (RuntimeException. " d2 error" ))))
543
+ executor)]
544
+
545
+ (is (thrown-with-msg? RuntimeException #"d1 error" @d2))))
528
546
529
547
(deftest test-when-complete
530
548
You can’t perform that action at this time.
0 commit comments