Commit b7ccdf65 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Dave Watson

Future API for CacheClientCommon

Summary:
Allow mutable functors in Promise::fulfil.

Facebook:
Works both with EventBase and without it (thanks to wangle::Future thread-safety). CacheClientImpl lifetime is guaranteed using shared_ptr.

Test Plan: unit test

Reviewed By: stepan@fb.com

FB internal diff: D1291024
parent dea4e166
......@@ -124,8 +124,8 @@ void Promise<T>::setValue() {
template <class T>
template <class F>
void Promise<T>::fulfil(const F& func) {
fulfilHelper(func);
void Promise<T>::fulfil(F&& func) {
fulfilHelper(std::forward<F>(func));
}
template <class T>
......@@ -133,7 +133,7 @@ template <class F>
typename std::enable_if<
std::is_convertible<typename std::result_of<F()>::type, T>::value &&
!std::is_same<T, void>::value>::type
inline Promise<T>::fulfilHelper(const F& func) {
inline Promise<T>::fulfilHelper(F&& func) {
throwIfFulfilled();
try {
setValue(func());
......@@ -147,7 +147,7 @@ template <class F>
typename std::enable_if<
std::is_same<typename std::result_of<F()>::type, void>::value &&
std::is_same<T, void>::value>::type
inline Promise<T>::fulfilHelper(const F& func) {
inline Promise<T>::fulfilHelper(F&& func) {
throwIfFulfilled();
try {
func();
......
......@@ -73,7 +73,7 @@ public:
p.fulfil([] { do something that may throw; return a T; });
*/
template <class F>
void fulfil(const F& func);
void fulfil(F&& func);
private:
typedef typename Future<T>::objPtr objPtr;
......@@ -91,13 +91,13 @@ private:
typename std::enable_if<
std::is_convertible<typename std::result_of<F()>::type, T>::value &&
!std::is_same<T, void>::value>::type
fulfilHelper(const F& func);
fulfilHelper(F&& func);
template <class F>
typename std::enable_if<
std::is_same<typename std::result_of<F()>::type, void>::value &&
std::is_same<T, void>::value>::type
fulfilHelper(const F& func);
fulfilHelper(F&& func);
};
}}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment