Commit 4d6d653e authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Add collectAllSemiFuture and implement collectAll in terms of it

Summary: This will allow incremental migration of `collectAll` to `collectAllSemiFuture`. Once everything is migrated to `collectAllSemiFuture`, `collectAll` will change to be the exact same as `collectAllSemiFuture`, then all uses will be moved back to `collectAll` and `collectAllSemiFuture` will be removed.

Reviewed By: yfeldblum

Differential Revision: D8015664

fbshipit-source-id: 07a154dc733fd7e1e003f4c103355e7b5d1ad1b5
parent 62c3a982
......@@ -1204,26 +1204,29 @@ void mapSetCallback(InputIterator first, InputIterator last, F func) {
// collectAll (variadic)
// TODO(T26439406): Make return SemiFuture
template <typename... Fs>
typename futures::detail::CollectAllVariadicContext<
typename std::decay<Fs>::type::value_type...>::type
collectAll(Fs&&... fs) {
collectAllSemiFuture(Fs&&... fs) {
auto ctx = std::make_shared<futures::detail::CollectAllVariadicContext<
typename std::decay<Fs>::type::value_type...>>();
futures::detail::collectVariadicHelper<
futures::detail::CollectAllVariadicContext>(ctx, std::forward<Fs>(fs)...);
return ctx->p.getSemiFuture().via(&folly::InlineExecutor::instance());
return ctx->p.getSemiFuture();
}
template <typename... Fs>
auto collectAll(Fs&&... fs) -> Future<typename decltype(
collectAllSemiFuture(std::forward<Fs&&>(fs)...))::value_type> {
return collectAllSemiFuture(std::forward<Fs>(fs)...).toUnsafeFuture();
}
// collectAll (iterator)
// TODO(T26439406): Make return SemiFuture
template <class InputIterator>
Future<
std::vector<
Try<typename std::iterator_traits<InputIterator>::value_type::value_type>>>
collectAll(InputIterator first, InputIterator last) {
SemiFuture<std::vector<
Try<typename std::iterator_traits<InputIterator>::value_type::value_type>>>
collectAllSemiFuture(InputIterator first, InputIterator last) {
typedef
typename std::iterator_traits<InputIterator>::value_type::value_type T;
......@@ -1241,7 +1244,14 @@ collectAll(InputIterator first, InputIterator last) {
mapSetCallback<T>(first, last, [ctx](size_t i, Try<T>&& t) {
ctx->results[i] = std::move(t);
});
return ctx->p.getSemiFuture().via(&folly::InlineExecutor::instance());
return ctx->p.getSemiFuture();
}
template <class InputIterator>
Future<std::vector<
Try<typename std::iterator_traits<InputIterator>::value_type::value_type>>>
collectAll(InputIterator first, InputIterator last) {
return collectAllSemiFuture(first, last).toUnsafeFuture();
}
// collect (iterator)
......
......@@ -41,7 +41,7 @@ struct CollectAllVariadicContext {
}
Promise<std::tuple<Try<Ts>...>> p;
std::tuple<Try<Ts>...> results;
typedef Future<std::tuple<Try<Ts>...>> type;
typedef SemiFuture<std::tuple<Try<Ts>...>> type;
};
template <typename... Ts>
......@@ -312,12 +312,23 @@ auto via(Executor*, Func&& func)
The return type for Future<T> input is a Future<std::vector<Try<T>>>
*/
template <class InputIterator>
SemiFuture<std::vector<
Try<typename std::iterator_traits<InputIterator>::value_type::value_type>>>
collectAllSemiFuture(InputIterator first, InputIterator last);
/// Sugar for the most common case
template <class Collection>
auto collectAllSemiFuture(Collection&& c)
-> decltype(collectAllSemiFuture(c.begin(), c.end())) {
return collectAllSemiFuture(c.begin(), c.end());
}
template <class InputIterator>
Future<std::vector<Try<
typename std::iterator_traits<InputIterator>::value_type::value_type>>>
collectAll(InputIterator first, InputIterator last);
/// Sugar for the most common case
template <class Collection>
auto collectAll(Collection&& c) -> decltype(collectAll(c.begin(), c.end())) {
return collectAll(c.begin(), c.end());
......@@ -330,7 +341,11 @@ auto collectAll(Collection&& c) -> decltype(collectAll(c.begin(), c.end())) {
template <typename... Fs>
typename futures::detail::CollectAllVariadicContext<
typename std::decay<Fs>::type::value_type...>::type
collectAll(Fs&&... fs);
collectAllSemiFuture(Fs&&... fs);
template <typename... Fs>
auto collectAll(Fs&&... fs) -> Future<typename decltype(
collectAllSemiFuture(std::forward<Fs&&>(fs)...))::value_type>;
/// Like collectAll, but will short circuit on the first exception. Thus, the
/// type of the returned Future is std::vector<T> instead of
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment