From b7ccdf65e931201fd160327976c8ec42b5a6c5b3 Mon Sep 17 00:00:00 2001 From: Andrii Grynenko Date: Tue, 22 Apr 2014 19:58:46 -0700 Subject: [PATCH] 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 --- folly/wangle/Promise-inl.h | 8 ++++---- folly/wangle/Promise.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/folly/wangle/Promise-inl.h b/folly/wangle/Promise-inl.h index 6e7e4947..49060270 100644 --- a/folly/wangle/Promise-inl.h +++ b/folly/wangle/Promise-inl.h @@ -124,8 +124,8 @@ void Promise::setValue() { template template -void Promise::fulfil(const F& func) { - fulfilHelper(func); +void Promise::fulfil(F&& func) { + fulfilHelper(std::forward(func)); } template @@ -133,7 +133,7 @@ template typename std::enable_if< std::is_convertible::type, T>::value && !std::is_same::value>::type -inline Promise::fulfilHelper(const F& func) { +inline Promise::fulfilHelper(F&& func) { throwIfFulfilled(); try { setValue(func()); @@ -147,7 +147,7 @@ template typename std::enable_if< std::is_same::type, void>::value && std::is_same::value>::type -inline Promise::fulfilHelper(const F& func) { +inline Promise::fulfilHelper(F&& func) { throwIfFulfilled(); try { func(); diff --git a/folly/wangle/Promise.h b/folly/wangle/Promise.h index f2a354fd..aae306c0 100644 --- a/folly/wangle/Promise.h +++ b/folly/wangle/Promise.h @@ -73,7 +73,7 @@ public: p.fulfil([] { do something that may throw; return a T; }); */ template - void fulfil(const F& func); + void fulfil(F&& func); private: typedef typename Future::objPtr objPtr; @@ -91,13 +91,13 @@ private: typename std::enable_if< std::is_convertible::type, T>::value && !std::is_same::value>::type - fulfilHelper(const F& func); + fulfilHelper(F&& func); template typename std::enable_if< std::is_same::type, void>::value && std::is_same::value>::type - fulfilHelper(const F& func); + fulfilHelper(F&& func); }; }} -- 2.34.1