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

Add a SemiFuture variant of collect

Summary: At least make it possible to do things correctly.

Reviewed By: yfeldblum, LeeHowes

Differential Revision: D14426753

fbshipit-source-id: 63b3572175224dbbda828981a5c9f067a5e35f33
parent 7ecfb621
...@@ -1572,9 +1572,9 @@ collectAll(InputIterator first, InputIterator last) { ...@@ -1572,9 +1572,9 @@ collectAll(InputIterator first, InputIterator last) {
// TODO(T26439406): Make return SemiFuture // TODO(T26439406): Make return SemiFuture
template <class InputIterator> template <class InputIterator>
Future<std::vector< SemiFuture<std::vector<
typename std::iterator_traits<InputIterator>::value_type::value_type>> typename std::iterator_traits<InputIterator>::value_type::value_type>>
collect(InputIterator first, InputIterator last) { collectSemiFuture(InputIterator first, InputIterator last) {
using F = typename std::iterator_traits<InputIterator>::value_type; using F = typename std::iterator_traits<InputIterator>::value_type;
using T = typename F::value_type; using T = typename F::value_type;
...@@ -1611,15 +1611,22 @@ collect(InputIterator first, InputIterator last) { ...@@ -1611,15 +1611,22 @@ collect(InputIterator first, InputIterator last) {
} }
}); });
} }
return ctx->p.getSemiFuture().via(&InlineExecutor::instance()); return ctx->p.getSemiFuture();
}
template <class InputIterator>
Future<std::vector<
typename std::iterator_traits<InputIterator>::value_type::value_type>>
collect(InputIterator first, InputIterator last) {
return collectSemiFuture(first, last).toUnsafeFuture();
} }
// collect (variadic) // collect (variadic)
// TODO(T26439406): Make return SemiFuture // TODO(T26439406): Make return SemiFuture
template <typename... Fs> template <typename... Fs>
Future<std::tuple<typename remove_cvref_t<Fs>::value_type...>> collect( SemiFuture<std::tuple<typename remove_cvref_t<Fs>::value_type...>>
Fs&&... fs) { collectSemiFuture(Fs&&... fs) {
using Result = std::tuple<typename remove_cvref_t<Fs>::value_type...>; using Result = std::tuple<typename remove_cvref_t<Fs>::value_type...>;
struct Context { struct Context {
~Context() { ~Context() {
...@@ -1646,7 +1653,13 @@ Future<std::tuple<typename remove_cvref_t<Fs>::value_type...>> collect( ...@@ -1646,7 +1653,13 @@ Future<std::tuple<typename remove_cvref_t<Fs>::value_type...>> collect(
}); });
}, },
static_cast<Fs&&>(fs)...); static_cast<Fs&&>(fs)...);
return ctx->p.getSemiFuture().via(&InlineExecutor::instance()); return ctx->p.getSemiFuture();
}
template <typename... Fs>
Future<std::tuple<typename remove_cvref_t<Fs>::value_type...>> collect(
Fs&&... fs) {
return collectSemiFuture(std::forward<Fs>(fs)...).toUnsafeFuture();
} }
// collectAny (iterator) // collectAny (iterator)
......
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