mirror of
https://github.com/clearlinux/folly.git
synced 2026-06-16 01:45:48 +00:00
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
This commit is contained in:
committed by
Viswanath Sivakumar
parent
ec66459bbd
commit
df7a2d078a
@@ -115,7 +115,7 @@ addTasks(InputIterator first, InputIterator last) {
|
||||
#endif
|
||||
addTask(
|
||||
[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.
|
||||
if (context->promise.hasValue()) {
|
||||
|
||||
@@ -309,7 +309,7 @@ struct FiberManager::AddTaskFinallyHelper {
|
||||
func_(std::move(func)), result_(finally.result_) {}
|
||||
|
||||
void operator()() {
|
||||
result_ = folly::makeTryFunction(std::move(func_));
|
||||
result_ = folly::makeTryWith(std::move(func_));
|
||||
|
||||
if (allocateInBuffer) {
|
||||
this->~Func();
|
||||
@@ -387,7 +387,7 @@ FiberManager::runInMainContextHelper(F&& func) {
|
||||
|
||||
folly::Try<Result> result;
|
||||
auto f = [&func, &result]() mutable {
|
||||
result = folly::makeTryFunction(std::forward<F>(func));
|
||||
result = folly::makeTryWith(std::forward<F>(func));
|
||||
};
|
||||
|
||||
immediateFunc_ = std::ref(f);
|
||||
|
||||
@@ -87,7 +87,7 @@ void Promise<T>::setValue() {
|
||||
template <class T>
|
||||
template <class F>
|
||||
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>
|
||||
template <class F>
|
||||
void Promise<T>::setWith(F&& func) {
|
||||
throwIfFulfilled();
|
||||
setTry(makeTryFunction(std::forward<F>(func)));
|
||||
setTry(makeTryWith(std::forward<F>(func)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ template <typename F>
|
||||
typename std::enable_if<
|
||||
!std::is_same<typename std::result_of<F()>::type, void>::value,
|
||||
Try<typename std::result_of<F()>::type>>::type
|
||||
makeTryFunction(F&& f) {
|
||||
makeTryWith(F&& f) {
|
||||
typedef typename std::result_of<F()>::type ResultType;
|
||||
try {
|
||||
return Try<ResultType>(f());
|
||||
@@ -143,7 +143,7 @@ template <typename F>
|
||||
typename std::enable_if<
|
||||
std::is_same<typename std::result_of<F()>::type, void>::value,
|
||||
Try<void>>::type
|
||||
makeTryFunction(F&& f) {
|
||||
makeTryWith(F&& f) {
|
||||
try {
|
||||
f();
|
||||
return Try<void>();
|
||||
|
||||
+3
-3
@@ -361,10 +361,10 @@ template <typename F>
|
||||
typename std::enable_if<
|
||||
!std::is_same<typename std::result_of<F()>::type, void>::value,
|
||||
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
|
||||
*
|
||||
@@ -374,7 +374,7 @@ template <typename F>
|
||||
typename std::enable_if<
|
||||
std::is_same<typename std::result_of<F()>::type, void>::value,
|
||||
Try<void>>::type
|
||||
makeTryFunction(F&& f);
|
||||
makeTryWith(F&& f);
|
||||
|
||||
} // folly
|
||||
|
||||
|
||||
@@ -34,41 +34,41 @@ TEST(Try, moveOnly) {
|
||||
v.reserve(10);
|
||||
}
|
||||
|
||||
TEST(Try, makeTryFunction) {
|
||||
TEST(Try, makeTryWith) {
|
||||
auto func = []() {
|
||||
return folly::make_unique<int>(1);
|
||||
};
|
||||
|
||||
auto result = makeTryFunction(func);
|
||||
auto result = makeTryWith(func);
|
||||
EXPECT_TRUE(result.hasValue());
|
||||
EXPECT_EQ(*result.value(), 1);
|
||||
}
|
||||
|
||||
TEST(Try, makeTryFunctionThrow) {
|
||||
TEST(Try, makeTryWithThrow) {
|
||||
auto func = []() {
|
||||
throw std::runtime_error("Runtime");
|
||||
return folly::make_unique<int>(1);
|
||||
};
|
||||
|
||||
auto result = makeTryFunction(func);
|
||||
auto result = makeTryWith(func);
|
||||
EXPECT_TRUE(result.hasException<std::runtime_error>());
|
||||
}
|
||||
|
||||
TEST(Try, makeTryFunctionVoid) {
|
||||
TEST(Try, makeTryWithVoid) {
|
||||
auto func = []() {
|
||||
return;
|
||||
};
|
||||
|
||||
auto result = makeTryFunction(func);
|
||||
auto result = makeTryWith(func);
|
||||
EXPECT_TRUE(result.hasValue());
|
||||
}
|
||||
|
||||
TEST(Try, makeTryFunctionVoidThrow) {
|
||||
TEST(Try, makeTryWithVoidThrow) {
|
||||
auto func = []() {
|
||||
throw std::runtime_error("Runtime");
|
||||
return;
|
||||
};
|
||||
|
||||
auto result = makeTryFunction(func);
|
||||
auto result = makeTryWith(func);
|
||||
EXPECT_TRUE(result.hasException<std::runtime_error>());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user