From: Andrii Grynenko Date: Wed, 23 Apr 2014 02:58:46 +0000 (-0700) Subject: Future API for CacheClientCommon X-Git-Tag: v0.22.0~585 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b7ccdf65e931201fd160327976c8ec42b5a6c5b3;p=folly.git 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 --- 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); }; }}