proxygen
ExecutorFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-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 
17 #pragma once
18 
19 #include <wangle/service/Service.h>
20 
21 namespace wangle {
22 
26 template <typename Req, typename Resp = Req>
27 class ExecutorFilter : public ServiceFilter<Req, Resp> {
28  public:
29  explicit ExecutorFilter(
30  std::shared_ptr<folly::Executor> exe,
31  std::shared_ptr<Service<Req, Resp>> service)
32  : ServiceFilter<Req, Resp>(service)
33  , exe_(exe) {}
34 
36  return via(exe_.get()).thenValue(
37  [req = std::move(req), this](auto&&) mutable {
38  return (*this->service_)(std::move(req));
39  });
40  }
41 
42  private:
43  std::shared_ptr<folly::Executor> exe_;
44 };
45 
46 } // namespace wangle
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
std::shared_ptr< Service< Req, Resp > > service_
Definition: Service.h:82
std::shared_ptr< folly::Executor > exe_
ExecutorFilter(std::shared_ptr< folly::Executor > exe, std::shared_ptr< Service< Req, Resp >> service)
InlineExecutor exe
Definition: Benchmark.cpp:337
folly::Future< Resp > operator()(Req req) override