2 * Copyright 2014 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 namespace folly { namespace wangle {
24 // forward declaration
25 template <class T> class Future;
34 Promise(Promise const&) = delete;
35 Promise& operator=(Promise const&) = delete;
38 Promise(Promise<T>&&);
39 Promise& operator=(Promise<T>&&);
41 /** Return a Future tied to the shared state. This can be called only
42 once, thereafter Future already retrieved exception will be raised. */
43 Future<T> getFuture();
45 /** Fulfil the Promise with an exception_ptr, e.g.
49 p.setException(std::current_exception());
52 void setException(std::exception_ptr const&);
54 /** Fulfil the Promise with an exception type E, which can be passed to
55 std::make_exception_ptr(). Useful for originating exceptions. If you
56 caught an exception the exception_ptr form is more appropriate.
58 template <class E> void setException(E const&);
60 /** Fulfil this Promise (only for Promise<void>) */
63 /** Set the value (use perfect forwarding for both move and copy) */
65 void setValue(M&& value);
67 void fulfilTry(Try<T>&& t);
69 /** Fulfil this Promise with the result of a function that takes no
70 arguments and returns something implicitly convertible to T.
71 Captures exceptions. e.g.
73 p.fulfil([] { do something that may throw; return a T; });
76 void fulfil(F&& func);
79 typedef typename Future<T>::statePtr statePtr;
81 // Whether the Future has been retrieved (a one-time operation).
84 // shared state object
87 void throwIfFulfilled();
88 void throwIfRetrieved();
94 #include "Promise-inl.h"