proxygen
FiberManager-inl.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-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 
19 #include <folly/futures/Promise.h>
20 
21 namespace folly {
22 namespace fibers {
23 
24 template <typename F>
27  using T = invoke_result_t<F>;
28  using FutureT = typename folly::lift_unit<T>::type;
29 
31  auto f = p.getFuture();
33  [func = std::forward<F>(func)]() mutable { return func(); },
34  [p = std::move(p)](folly::Try<T>&& t) mutable {
35  p.setTry(std::move(t));
36  });
37  return f;
38 }
39 
40 template <typename F>
44  auto f = p.getFuture();
45  addTaskRemote(
46  [p = std::move(p), func = std::forward<F>(func), this]() mutable {
47  auto t = folly::makeTryWith(std::forward<F>(func));
48  runInMainContext([&]() { p.setTry(std::move(t)); });
49  });
50  return f;
51 }
52 } // namespace fibers
53 } // namespace folly
auto f
typename invoke_result< F, Args... >::type invoke_result_t
Definition: Invoke.h:142
PskType type
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::std T
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void addTaskFinally(F &&func, G &&finally)
void setTry(Try< T > &&t)
Definition: Promise-inl.h:122
auto addTaskFuture(F &&func) -> folly::Future< typename folly::lift_unit< invoke_result_t< F >>::type >
Future< T > getFuture()
Definition: Promise-inl.h:97
Definition: Try.h:51
invoke_result_t< F > runInMainContext(F &&func)
std::enable_if< !std::is_same< invoke_result_t< F >, void >::value, Try< invoke_result_t< F > > >::type makeTryWith(F &&f)
Definition: Try-inl.h:223
auto addTaskRemoteFuture(F &&func) -> folly::Future< typename folly::lift_unit< invoke_result_t< F >>::type >