~smspillaz/folly/folly-git-master

« back to all changes in this revision

Viewing changes to folly/experimental/coro/detail/Traits.h

  • Committer: Facebook Github Bot
  • Author(s): Lewis Baker
  • Date: 2019-03-19 21:21:59 UTC
  • Revision ID: git-v1:3874d4233f52913e000a73dc0e7442106e21c4fa
Add variadic folly::coro::collectAlll() and collectAllTry()

Summary:
Adds two new functions to folly::coro for concurrently awaiting a fixed number of sub-tasks.

* `folly::coro::collectAll(tasks...)`
* `folly::coro::collectAllTry(tasks...)`

Both can be used to concurrently await multiple input tasks. The difference is in how they report the results.

`collectAll()` produces a tuple of the result values for each of the input operations. If any of the input operations fails with an exception then the whole operation fails with an exception (which one is unspecified) any successful results are discarded.

`collectAllTry()` produces a tuple of `Try<T>` objects regardless of whether any of the input operations failed with an exception. The individual result objects can then be queried for the success/failure, allowing the caller to handle partial failure and/or determine which operation(s) failed.

Reviewed By: andriigrynenko

Differential Revision: D14334714

fbshipit-source-id: 22eb51e2198be42e77677a066bfbc15e1c7eb7dd

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
namespace detail {
23
23
 
24
24
/**
 
25
 * A type trait that lifts lvalue references into std::reference_wrapper<T>
 
26
 * eg. so the value can be stored in std::optional or folly::Try.
 
27
 */
 
28
template <typename T>
 
29
struct lift_lvalue_reference {
 
30
  using type = T;
 
31
};
 
32
 
 
33
template <typename T>
 
34
struct lift_lvalue_reference<T&> {
 
35
  using type = std::reference_wrapper<T>;
 
36
};
 
37
 
 
38
template <typename T>
 
39
using lift_lvalue_reference_t = typename lift_lvalue_reference<T>::type;
 
40
 
 
41
/**
25
42
 * A type trait to decay rvalue-reference types to a prvalue.
26
43
 */
27
44
template <typename T>