proxygen
set_error_2.cpp File Reference

Go to the source code of this file.

Functions

int main ()
 

Variables

template<class T , class E = std::exception_ptr>
auto concat
 

Function Documentation

int main ( void  )

Definition at line 40 of file set_error_2.cpp.

References folly::empty(), folly::pushmi::operators::error(), folly::pushmi::operators::just, folly::pushmi::operators::no_fail, folly::pushmi::__adl::noexcept(), folly::pushmi::on_error(), submit, folly::pushmi::operators::switch_on_error, and folly::pushmi::operators::transform.

40  {
41  auto stop_abort = mi::on_error([](auto) noexcept {});
42  // support all error value types
43 
44  op::error(std::exception_ptr{}) | op::submit(stop_abort);
45 
46  op::error(std::errc::argument_list_too_long) | op::submit(stop_abort);
47 
48  // transform an error
49 
50  op::error(std::errc::argument_list_too_long) | op::switch_on_error([
51  ](auto) noexcept { return op::error(std::exception_ptr{}); }) |
52  op::submit(stop_abort);
53 
54  // use default value if an error occurs
55 
56  op::just(42) |
57  op::switch_on_error([](auto) noexcept { return op::just(0); }) |
58  op::submit();
59 
60  // suppress if an error occurs
61 
62  op::error(std::errc::argument_list_too_long) |
63  op::switch_on_error([](auto) noexcept { return op::empty(); }) |
64  op::submit();
65 
66  // abort if an error occurs
67 
68  op::just(42) | op::no_fail() | op::submit();
69 
70  // transform value to error_
71 
72  op::just(42) | op::transform([](auto v) {
74  if (v < 40) {
75  return r_t{op::error<int>(std::exception_ptr{})};
76  } else {
77  return r_t{op::just(v)};
78  }
79  }) | concat<int> |
80  op::submit();
81 
82  // retry on error
83 
84  // http.get(ex) |
85  // op::timeout(ex, 1s) |
86  // op::switch_on_error([](auto e) noexcept { return op::timer(ex, 1s); }) |
87  // op::repeat() |
88  // op::timeout(ex, 10s) |
89  // op::submit();
90 
91  std::cout << "OK" << std::endl;
92 }
PUSHMI_INLINE_VAR constexpr detail::switch_on_error_fn switch_on_error
auto on_error(Fns...fns) -> on_error_fn< Fns... >
Definition: boosters.h:273
requires E e noexcept(noexcept(s.error(std::move(e))))
PUSHMI_INLINE_VAR constexpr detail::transform_fn transform
Definition: transform.h:158
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::just_fn just
PUSHMI_INLINE_VAR constexpr detail::no_fail_fn no_fail
Definition: no_fail.h:59

Variable Documentation

template<class T , class E = std::exception_ptr>
auto concat
Initial value:
= [](auto in) {
return mi::make_single_sender([in](auto out) mutable {
mi::submit(in, mi::make_receiver(out, [](auto out, auto v) {
}));
});
}
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_receiver_fn make_receiver
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_single_sender_fn make_single_sender

Definition at line 32 of file set_error_2.cpp.