|
1543 | 1543 | (when (nil? value#)
|
1544 | 1544 | (throw (NullPointerException. ~(str value " was null"))))))))
|
1545 | 1545 |
|
1546 |
| -(defn- map-deferred |
| 1546 | +(defn- fmap-deferred |
1547 | 1547 | "Like map/fmap but for deferreds.
|
1548 | 1548 |
|
1549 | 1549 | This function does not unwrap the result of f"
|
|
1554 | 1554 | (fn [error] (error! d' error)))
|
1555 | 1555 | d'))
|
1556 | 1556 |
|
1557 |
| -(defn- mapcat-deferred |
1558 |
| - "Like map-deferred but it unwraps exactly one level from the result of f" |
1559 |
| - [d f] |
1560 |
| - (let [d' (deferred)] |
1561 |
| - (on-realized d |
1562 |
| - (fn [val] |
1563 |
| - (on-realized (->deferred (f val)) |
1564 |
| - #(success! d' %) |
1565 |
| - #(error! d' %))) |
1566 |
| - (fn [error] (error! d' error))) |
1567 |
| - d')) |
1568 | 1557 |
|
1569 | 1558 | (defn- then-apply [d ^Function f]
|
1570 | 1559 | (assert-some f)
|
1571 |
| - (map-deferred d #(.apply f %))) |
| 1560 | + (fmap-deferred d #(.apply f %))) |
1572 | 1561 |
|
1573 | 1562 | (def-async-for then-apply)
|
1574 | 1563 |
|
1575 | 1564 | (defn- then-accept [d ^Consumer c]
|
1576 | 1565 | (assert-some c)
|
1577 |
| - (map-deferred d #(.accept c %))) |
| 1566 | + (fmap-deferred d #(.accept c %))) |
1578 | 1567 |
|
1579 | 1568 | (def-async-for then-accept)
|
1580 | 1569 |
|
1581 | 1570 | (defn- then-run [d ^Runnable f]
|
1582 | 1571 | (assert-some f)
|
1583 |
| - (map-deferred d (fn [_] (.run f)))) |
| 1572 | + (fmap-deferred d (fn [_] (.run f)))) |
1584 | 1573 |
|
1585 | 1574 | (def-async-for then-run)
|
1586 | 1575 |
|
1587 | 1576 |
|
1588 | 1577 | (defn- then-combine [d other ^BiFunction f]
|
1589 | 1578 | (assert-some other f)
|
1590 |
| - (map-deferred (zip d other) |
| 1579 | + (fmap-deferred (zip d other) |
1591 | 1580 | (fn [[x y]] (.apply f x y))))
|
1592 | 1581 |
|
1593 | 1582 | (def-async-for-dual then-combine)
|
1594 | 1583 |
|
1595 | 1584 |
|
1596 | 1585 | (defn- then-accept-both [d other ^BiConsumer f]
|
1597 | 1586 | (assert-some other f)
|
1598 |
| - (map-deferred (zip d other) |
| 1587 | + (fmap-deferred (zip d other) |
1599 | 1588 | (fn [[x y]] (.accept f x y))))
|
1600 | 1589 |
|
1601 | 1590 | (def-async-for-dual then-accept-both)
|
1602 | 1591 |
|
1603 | 1592 |
|
1604 | 1593 | (defn- run-after-both [d other ^Runnable f]
|
1605 | 1594 | (assert-some other f)
|
1606 |
| - (map-deferred (zip d other) |
| 1595 | + (fmap-deferred (zip d other) |
1607 | 1596 | (fn [[_ _]] (.run f))))
|
1608 | 1597 |
|
1609 | 1598 |
|
|
1633 | 1622 |
|
1634 | 1623 | (defn- then-compose [d ^Function f]
|
1635 | 1624 | (assert-some f)
|
1636 |
| - (mapcat-deferred d (fn [value] (.apply f value)))) |
| 1625 | + (let [d' (deferred)] |
| 1626 | + (on-realized d |
| 1627 | + (fn [val] |
| 1628 | + (on-realized (->deferred (.apply f val)) |
| 1629 | + #(success! d' %) |
| 1630 | + #(error! d' %))) |
| 1631 | + (fn [error] (error! d' error))) |
| 1632 | + d')) |
1637 | 1633 |
|
1638 | 1634 | (def-async-for then-compose)
|
1639 | 1635 |
|
|
0 commit comments