error.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. /*
  3. * Copyright 2018-present Facebook, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include <folly/experimental/pushmi/o/extension_operators.h>
  18. #include <folly/experimental/pushmi/o/submit.h>
  19. namespace pushmi {
  20. namespace detail {
  21. struct single_error_sender_base : single_sender<ignoreSF, inlineEXF> {
  22. using properties = property_set<
  23. is_sender<>,
  24. is_single<>,
  25. is_always_blocking<>,
  26. is_fifo_sequence<>>;
  27. };
  28. template <class E, class... VN>
  29. struct single_error_impl {
  30. E e_;
  31. PUSHMI_TEMPLATE(class Out)
  32. (requires ReceiveError<Out, E>&& ReceiveValue<Out, VN...>)
  33. void operator()(
  34. single_error_sender_base&,
  35. Out out) {
  36. ::pushmi::set_error(out, std::move(e_));
  37. }
  38. };
  39. } // namespace detail
  40. namespace operators {
  41. PUSHMI_TEMPLATE(class... VN, class E)
  42. (requires And<SemiMovable<VN>...>&& SemiMovable<E>)
  43. auto error(E e) {
  44. return make_single_sender(
  45. detail::single_error_sender_base{},
  46. detail::single_error_impl<E, VN...>{std::move(e)});
  47. }
  48. } // namespace operators
  49. } // namespace pushmi