| 1574 | template <typename T> |
| 1575 | template <typename X> |
| 1576 | Future<X> Future<T>::then(lambda::CallableOnce<Future<X>(const T&)> f) const |
| 1577 | { |
| 1578 | std::unique_ptr<Promise<X>> promise(new Promise<X>()); |
| 1579 | Future<X> future = promise->future(); |
| 1580 | |
| 1581 | lambda::CallableOnce<void(const Future<T>&)> thenf = lambda::partial( |
| 1582 | &internal::thenf<T, X>, std::move(f), std::move(promise), lambda::_1); |
| 1583 | |
| 1584 | onAny(std::move(thenf)); |
| 1585 | |
| 1586 | onAbandoned([=]() mutable { |
| 1587 | future.abandon(); |
| 1588 | }); |
| 1589 | |
| 1590 | // Propagate discarding up the chain. To avoid cyclic dependencies, |
| 1591 | // we keep a weak future in the callback. |
| 1592 | future.onDiscard(lambda::bind(&internal::discard<T>, WeakFuture<T>(*this))); |
| 1593 | |
| 1594 | return future; |
| 1595 | } |
| 1596 | |
| 1597 | |
| 1598 | template <typename T> |