proxygen
via.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
21 
22 namespace folly {
23 namespace pushmi {
24 
25 namespace detail {
26 
27 template <class Executor>
28 struct via_fn_base {
30  bool done;
31  explicit via_fn_base(Executor ex) : exec(std::move(ex)), done(false) {}
33  return *this;
34  }
35 };
36 template <class Executor, class Out>
37 struct via_fn_data : public Out, public via_fn_base<Executor> {
39  : Out(std::move(out)), via_fn_base<Executor>(std::move(exec)) {}
40 
41  using Out::done;
42  using Out::error;
43  using typename Out::properties;
44 };
45 
46 template <class Out, class Executor>
48  return {std::move(out), std::move(ex)};
49 }
50 
51 struct via_fn {
52  private:
53  template <class Out>
54  struct on_value_impl {
55  template <class V>
56  struct impl {
57  V v_;
58  Out out_;
59  void operator()(any) {
60  set_value(out_, std::move(v_));
61  }
62  };
63  template <class Data, class V>
64  void operator()(Data& data, V&& v) const {
65  if (data.via_fn_base_ref().done) {
66  return;
67  }
68  submit(
69  data.via_fn_base_ref().exec,
70  ::folly::pushmi::make_receiver(impl<std::decay_t<V>>{
71  (V &&) v, std::move(static_cast<Out&>(data))}));
72  }
73  };
74  template <class Out>
75  struct on_error_impl {
76  template <class E>
77  struct impl {
78  E e_;
79  Out out_;
81  set_error(out_, std::move(e_));
82  }
83  };
84  template <class Data, class E>
85  void operator()(Data& data, E e) const noexcept {
86  if (data.via_fn_base_ref().done) {
87  return;
88  }
89  data.via_fn_base_ref().done = true;
90  submit(
91  data.via_fn_base_ref().exec,
93  impl<E>{std::move(e), std::move(static_cast<Out&>(data))}));
94  }
95  };
96  template <class Out>
97  struct on_done_impl {
98  struct impl {
99  Out out_;
100  void operator()(any) {
101  set_done(out_);
102  }
103  };
104  template <class Data>
105  void operator()(Data& data) const {
106  if (data.via_fn_base_ref().done) {
107  return;
108  }
109  data.via_fn_base_ref().done = true;
110  submit(
111  data.via_fn_base_ref().exec,
113  impl{std::move(static_cast<Out&>(data))}));
114  }
115  };
116  template <class In, class ExecutorFactory>
117  struct executor_impl {
118  ExecutorFactory ef_;
119  template <class Data>
120  auto operator()(Data&) const {
121  return ef_();
122  }
123  };
124  template <class In, class ExecutorFactory>
125  struct out_impl {
126  ExecutorFactory ef_;
127  PUSHMI_TEMPLATE(class Out)
128  (requires Receiver<Out>)
129  auto operator()(Out out) const {
130  auto exec = ef_();
131  return ::folly::pushmi::detail::receiver_from_fn<In>()(
136  }
137  };
138  template <class ExecutorFactory>
139  struct in_impl {
140  ExecutorFactory ef_;
141  PUSHMI_TEMPLATE(class In)
142  (requires Sender<In>)
143  auto operator()(In in) const {
145  std::move(in),
146  ::folly::pushmi::detail::submit_transform_out<In>(
150  }
151  };
152 
153  public:
154  PUSHMI_TEMPLATE(class ExecutorFactory)
155  (requires Invocable<ExecutorFactory&>&&
157  FifoSequence<invoke_result_t<ExecutorFactory&>>)
158  auto operator()(ExecutorFactory ef) const {
160  }
161 };
162 
163 } // namespace detail
164 
165 namespace operators {
167 } // namespace operators
168 
169 } // namespace pushmi
170 } // namespace folly
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto on_executor(Fn fn) -> on_executor_fn< Fn >
Definition: boosters.h:307
STL namespace.
PUSHMI_INLINE_VAR constexpr __adl::set_error_fn set_error
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
void operator()(Data &data) const
Definition: via.h:105
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
requires requires(::folly::pushmi::invoke(std::declval< F >(), std::get< Is >(std::declval< Tuple >())...))) const expr decltype(auto) apply_impl(F &&f
#define PUSHMI_INLINE_VAR
Definition: concept_def.h:60
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::detail::sender_from_fn sender_from
void operator()(Data &data, V &&v) const
Definition: via.h:64
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
Definition: Future-inl.h:1290
void operator()(Data &data, E e) const noexcept
Definition: via.h:85
PUSHMI_INLINE_VAR constexpr __adl::do_submit_fn submit
PUSHMI_TEMPLATE(class In, class Out, bool SenderRequires, bool SingleSenderRequires, bool TimeSingleSenderRequires)(requires Sender< In > &&Receiver< Out >) constexpr bool sender_requires_from()
via_fn_base & via_fn_base_ref()
Definition: via.h:32
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_receiver_fn make_receiver
via_fn_data(Out out, Executor exec)
Definition: via.h:38
auto make_via_fn_data(Out out, Executor ex) -> via_fn_data< Executor, Out >
Definition: via.h:47
PUSHMI_INLINE_VAR constexpr __adl::set_done_fn set_done