proxygen
Promise.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 
18 #include <folly/Try.h>
19 #include <folly/fibers/traits.h>
21 
22 namespace folly {
23 namespace fibers {
24 
25 class Baton;
26 
27 template <typename T, typename BatonT = Baton>
28 class Promise {
29  public:
30  typedef T value_type;
31  typedef BatonT baton_type;
32 
33  ~Promise();
34 
35  // not copyable
36  Promise(const Promise&) = delete;
37  Promise& operator=(const Promise&) = delete;
38 
39  // movable
41  Promise& operator=(Promise&&);
42 
44  void setValue();
45 
47  template <class M>
48  void setValue(M&& value);
49 
55  void setTry(folly::Try<T>&& t);
56 
63  template <class F>
64  void setWith(F&& func);
65 
73 
81  template <class F>
82  static value_type await(F&& func);
83 
84  private:
85  Promise(folly::Try<T>& value, BatonT& baton);
87  BatonT* baton_;
88 
89  void throwIfFulfilled() const;
90 
91  template <class F>
92  typename std::enable_if<
93  std::is_convertible<invoke_result_t<F>, T>::value &&
94  !std::is_same<T, void>::value>::type
95  fulfilHelper(F&& func);
96 
97  template <class F>
98  typename std::enable_if<
99  std::is_same<invoke_result_t<F>, void>::value &&
100  std::is_same<T, void>::value>::type
101  fulfilHelper(F&& func);
102 };
103 } // namespace fibers
104 } // namespace folly
105 
106 #include <folly/fibers/Promise-inl.h>
void setTry(folly::Try< T > &&t)
Definition: Promise-inl.h:60
void setWith(F &&func)
Definition: Promise-inl.h:88
typename invoke_result< F, Args... >::type invoke_result_t
Definition: Invoke.h:142
PskType type
STL namespace.
folly::Try< T > * value_
Definition: Promise.h:86
folly::std T
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
void setException(folly::exception_wrapper)
Definition: Promise-inl.h:55
std::enable_if< std::is_convertible< invoke_result_t< F >, T >::value &&!std::is_same< T, void >::value >::type fulfilHelper(F &&func)
Definition: Try.h:51
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for M
Definition: Hazptr.h:104
Promise(const Promise &)=delete
void throwIfFulfilled() const
Definition: Promise-inl.h:40
const
Definition: upload.py:398
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
static value_type await(F &&func)
Definition: Promise-inl.h:94
Promise & operator=(const Promise &)=delete