Commit df7a2d07 authored by James Sedgwick's avatar James Sedgwick Committed by Viswanath Sivakumar

makeTryFunction -> makeTryWith codemod

Summary: This is more consistent with setWith, makeFutureWith, etc

Test Plan: unit

Reviewed By: hans@fb.com

Subscribers: folly-diffs@, jsedgwick, yfeldblum, chalfant

FB internal diff: D2064667

Signature: t1:2064667:1431541614:a0e3f23d5effde13a93ce58ca3e21c7c3575215c
parent ec66459b
...@@ -115,7 +115,7 @@ addTasks(InputIterator first, InputIterator last) { ...@@ -115,7 +115,7 @@ addTasks(InputIterator first, InputIterator last) {
#endif #endif
addTask( addTask(
[i, context, f = std::move(*first)]() { [i, context, f = std::move(*first)]() {
context->results.emplace_back(i, folly::makeTryFunction(std::move(f))); context->results.emplace_back(i, folly::makeTryWith(std::move(f)));
// Check for awaiting iterator. // Check for awaiting iterator.
if (context->promise.hasValue()) { if (context->promise.hasValue()) {
......
...@@ -309,7 +309,7 @@ struct FiberManager::AddTaskFinallyHelper { ...@@ -309,7 +309,7 @@ struct FiberManager::AddTaskFinallyHelper {
func_(std::move(func)), result_(finally.result_) {} func_(std::move(func)), result_(finally.result_) {}
void operator()() { void operator()() {
result_ = folly::makeTryFunction(std::move(func_)); result_ = folly::makeTryWith(std::move(func_));
if (allocateInBuffer) { if (allocateInBuffer) {
this->~Func(); this->~Func();
...@@ -387,7 +387,7 @@ FiberManager::runInMainContextHelper(F&& func) { ...@@ -387,7 +387,7 @@ FiberManager::runInMainContextHelper(F&& func) {
folly::Try<Result> result; folly::Try<Result> result;
auto f = [&func, &result]() mutable { auto f = [&func, &result]() mutable {
result = folly::makeTryFunction(std::forward<F>(func)); result = folly::makeTryWith(std::forward<F>(func));
}; };
immediateFunc_ = std::ref(f); immediateFunc_ = std::ref(f);
......
...@@ -87,7 +87,7 @@ void Promise<T>::setValue() { ...@@ -87,7 +87,7 @@ void Promise<T>::setValue() {
template <class T> template <class T>
template <class F> template <class F>
void Promise<T>::setWith(F&& func) { void Promise<T>::setWith(F&& func) {
setTry(makeTryFunction(std::forward<F>(func))); setTry(makeTryWith(std::forward<F>(func)));
} }
}} }}
...@@ -127,7 +127,7 @@ template <class T> ...@@ -127,7 +127,7 @@ template <class T>
template <class F> template <class F>
void Promise<T>::setWith(F&& func) { void Promise<T>::setWith(F&& func) {
throwIfFulfilled(); throwIfFulfilled();
setTry(makeTryFunction(std::forward<F>(func))); setTry(makeTryWith(std::forward<F>(func)));
} }
} }
...@@ -128,7 +128,7 @@ template <typename F> ...@@ -128,7 +128,7 @@ template <typename F>
typename std::enable_if< typename std::enable_if<
!std::is_same<typename std::result_of<F()>::type, void>::value, !std::is_same<typename std::result_of<F()>::type, void>::value,
Try<typename std::result_of<F()>::type>>::type Try<typename std::result_of<F()>::type>>::type
makeTryFunction(F&& f) { makeTryWith(F&& f) {
typedef typename std::result_of<F()>::type ResultType; typedef typename std::result_of<F()>::type ResultType;
try { try {
return Try<ResultType>(f()); return Try<ResultType>(f());
...@@ -143,7 +143,7 @@ template <typename F> ...@@ -143,7 +143,7 @@ template <typename F>
typename std::enable_if< typename std::enable_if<
std::is_same<typename std::result_of<F()>::type, void>::value, std::is_same<typename std::result_of<F()>::type, void>::value,
Try<void>>::type Try<void>>::type
makeTryFunction(F&& f) { makeTryWith(F&& f) {
try { try {
f(); f();
return Try<void>(); return Try<void>();
......
...@@ -361,10 +361,10 @@ template <typename F> ...@@ -361,10 +361,10 @@ template <typename F>
typename std::enable_if< typename std::enable_if<
!std::is_same<typename std::result_of<F()>::type, void>::value, !std::is_same<typename std::result_of<F()>::type, void>::value,
Try<typename std::result_of<F()>::type>>::type Try<typename std::result_of<F()>::type>>::type
makeTryFunction(F&& f); makeTryWith(F&& f);
/* /*
* Specialization of makeTryFunction for void * Specialization of makeTryWith for void
* *
* @param f a function to execute and capture the result of * @param f a function to execute and capture the result of
* *
...@@ -374,7 +374,7 @@ template <typename F> ...@@ -374,7 +374,7 @@ template <typename F>
typename std::enable_if< typename std::enable_if<
std::is_same<typename std::result_of<F()>::type, void>::value, std::is_same<typename std::result_of<F()>::type, void>::value,
Try<void>>::type Try<void>>::type
makeTryFunction(F&& f); makeTryWith(F&& f);
} // folly } // folly
......
...@@ -34,41 +34,41 @@ TEST(Try, moveOnly) { ...@@ -34,41 +34,41 @@ TEST(Try, moveOnly) {
v.reserve(10); v.reserve(10);
} }
TEST(Try, makeTryFunction) { TEST(Try, makeTryWith) {
auto func = []() { auto func = []() {
return folly::make_unique<int>(1); return folly::make_unique<int>(1);
}; };
auto result = makeTryFunction(func); auto result = makeTryWith(func);
EXPECT_TRUE(result.hasValue()); EXPECT_TRUE(result.hasValue());
EXPECT_EQ(*result.value(), 1); EXPECT_EQ(*result.value(), 1);
} }
TEST(Try, makeTryFunctionThrow) { TEST(Try, makeTryWithThrow) {
auto func = []() { auto func = []() {
throw std::runtime_error("Runtime"); throw std::runtime_error("Runtime");
return folly::make_unique<int>(1); return folly::make_unique<int>(1);
}; };
auto result = makeTryFunction(func); auto result = makeTryWith(func);
EXPECT_TRUE(result.hasException<std::runtime_error>()); EXPECT_TRUE(result.hasException<std::runtime_error>());
} }
TEST(Try, makeTryFunctionVoid) { TEST(Try, makeTryWithVoid) {
auto func = []() { auto func = []() {
return; return;
}; };
auto result = makeTryFunction(func); auto result = makeTryWith(func);
EXPECT_TRUE(result.hasValue()); EXPECT_TRUE(result.hasValue());
} }
TEST(Try, makeTryFunctionVoidThrow) { TEST(Try, makeTryWithVoidThrow) {
auto func = []() { auto func = []() {
throw std::runtime_error("Runtime"); throw std::runtime_error("Runtime");
return; return;
}; };
auto result = makeTryFunction(func); auto result = makeTryWith(func);
EXPECT_TRUE(result.hasException<std::runtime_error>()); EXPECT_TRUE(result.hasException<std::runtime_error>());
} }
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