Commit ebc7dd0d authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot 8

Don't require folly::Unit in addTaskFinally

Summary:
In D3241498 addTaskFuture was fixed to work with function returning void. This however changed addTaskFinally API to not allow finally functor which accepts Try<void>.

folly::fibers generally supports Try<void> so there's no reason to force users to use folly::Unit instead of void for addTaskFinally too.

Reviewed By: yfeldblum

Differential Revision: D3243893

fb-gh-sync-id: d1df54738157d2019120103956f59b3971ba25ff
fbshipit-source-id: d1df54738157d2019120103956f59b3971ba25ff
parent b31eb722
......@@ -283,9 +283,10 @@ void FiberManager::addTask(F&& func) {
template <typename F>
auto FiberManager::addTaskFuture(F&& func) -> folly::Future<
typename folly::Unit::Lift<typename std::result_of<F()>::type>::type> {
using T =
typename folly::Unit::Lift<typename std::result_of<F()>::type>::type;
folly::Promise<T> p;
using T = typename std::result_of<F()>::type;
using FutureT = typename folly::Unit::Lift<T>::type;
folly::Promise<FutureT> p;
auto f = p.getFuture();
addTaskFinally(
[func = std::forward<F>(func)]() mutable { return func(); },
......@@ -398,8 +399,7 @@ struct FiberManager::AddTaskFinallyHelper {
template <typename F, typename G>
void FiberManager::addTaskFinally(F&& func, G&& finally) {
typedef typename folly::Unit::Lift<typename std::result_of<F()>::type>::type
Result;
typedef typename std::result_of<F()>::type Result;
static_assert(
IsRvalueRefTry<typename FirstArgOf<G>::type>::value,
......
......@@ -244,6 +244,11 @@ class Try {
template <>
class Try<void> {
public:
/*
* The value type for the Try
*/
typedef void element_type;
// Construct a Try holding a successful and void result
Try() : hasValue_(true) {}
......
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