mirror of
https://github.com/BlackMATov/promise.hpp.git
synced 2025-12-16 22:19:38 +07:00
rename fail to except
This commit is contained in:
26
promise.hpp
26
promise.hpp
@@ -238,7 +238,7 @@ namespace promise_hpp
|
||||
}
|
||||
|
||||
template < typename RejectF >
|
||||
promise<T> fail(RejectF&& on_reject) {
|
||||
promise<T> except(RejectF&& on_reject) {
|
||||
return then(
|
||||
[](const T& value) { return value; },
|
||||
std::forward<RejectF>(on_reject));
|
||||
@@ -540,7 +540,7 @@ namespace promise_hpp
|
||||
}
|
||||
|
||||
template < typename RejectF >
|
||||
promise<void> fail(RejectF&& on_reject) {
|
||||
promise<void> except(RejectF&& on_reject) {
|
||||
return then(
|
||||
[]{},
|
||||
std::forward<RejectF>(on_reject));
|
||||
@@ -727,16 +727,12 @@ namespace promise_hpp
|
||||
promise<R> make_promise(F&& f) {
|
||||
promise<R> result;
|
||||
|
||||
auto resolver = [
|
||||
p = result
|
||||
](auto&& v) mutable {
|
||||
return p.resolve(std::forward<decltype(v)>(v));
|
||||
auto resolver = [result](auto&& v) mutable {
|
||||
return result.resolve(std::forward<decltype(v)>(v));
|
||||
};
|
||||
|
||||
auto rejector = [
|
||||
p = result
|
||||
](auto&& e) mutable {
|
||||
return p.reject(std::forward<decltype(e)>(e));
|
||||
auto rejector = [result](auto&& e) mutable {
|
||||
return result.reject(std::forward<decltype(e)>(e));
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -825,9 +821,7 @@ namespace promise_hpp
|
||||
if ( context->apply_result(result_index, v) ) {
|
||||
resolver(std::move(context->results));
|
||||
}
|
||||
}).fail([rejector](std::exception_ptr e) mutable {
|
||||
rejector(e);
|
||||
});
|
||||
}, rejector);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -854,11 +848,7 @@ namespace promise_hpp
|
||||
|
||||
return make_promise<child_promise_value_t>([begin, end](auto&& resolver, auto&& rejector){
|
||||
for ( auto iter = begin; iter != end; ++iter ) {
|
||||
(*iter).then([resolver](const child_promise_value_t& v) mutable {
|
||||
resolver(v);
|
||||
}).fail([rejector](std::exception_ptr e) mutable {
|
||||
rejector(e);
|
||||
});
|
||||
(*iter).then(resolver, rejector);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
50
tests.cpp
50
tests.cpp
@@ -118,7 +118,7 @@ TEST_CASE("promise") {
|
||||
int check_42_int = 0;
|
||||
auto p = pr::promise<int>();
|
||||
p.resolve(42);
|
||||
p.fail([](std::exception_ptr){
|
||||
p.except([](std::exception_ptr){
|
||||
}).then([&check_42_int](int value){
|
||||
check_42_int = value;
|
||||
});
|
||||
@@ -155,7 +155,7 @@ TEST_CASE("promise") {
|
||||
p.then([¬_call_then_on_reject](int value) {
|
||||
(void)value;
|
||||
not_call_then_on_reject = false;
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(not_call_then_on_reject);
|
||||
@@ -167,7 +167,7 @@ TEST_CASE("promise") {
|
||||
auto p = pr::promise<int>();
|
||||
p.reject(ee);
|
||||
p.then([](int){
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(call_fail_with_logic_error);
|
||||
@@ -178,7 +178,7 @@ TEST_CASE("promise") {
|
||||
auto p = pr::promise<int>();
|
||||
p.reject(std::make_exception_ptr(ee));
|
||||
p.then([](int){
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(call_fail_with_logic_error);
|
||||
@@ -187,9 +187,9 @@ TEST_CASE("promise") {
|
||||
int check_multi_fail = 0;
|
||||
auto p = pr::promise<>();
|
||||
p.reject(std::logic_error("hello fail"));
|
||||
p.fail([&check_multi_fail](std::exception_ptr){
|
||||
p.except([&check_multi_fail](std::exception_ptr){
|
||||
++check_multi_fail;
|
||||
}).fail([&check_multi_fail](std::exception_ptr){
|
||||
}).except([&check_multi_fail](std::exception_ptr){
|
||||
++check_multi_fail;
|
||||
});
|
||||
REQUIRE(check_multi_fail == 2);
|
||||
@@ -219,7 +219,7 @@ TEST_CASE("promise") {
|
||||
auto p = pr::promise<int>();
|
||||
p.then([¬_call_then_on_reject](int){
|
||||
not_call_then_on_reject = false;
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(not_call_then_on_reject);
|
||||
@@ -249,7 +249,7 @@ TEST_CASE("promise") {
|
||||
(void)resolve;
|
||||
reject(std::logic_error("hello fail"));
|
||||
});
|
||||
p.fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
p.except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(call_fail_with_logic_error);
|
||||
@@ -261,7 +261,7 @@ TEST_CASE("promise") {
|
||||
(void)reject;
|
||||
throw std::logic_error("hello fail");
|
||||
});
|
||||
p.fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
p.except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(call_fail_with_logic_error);
|
||||
@@ -289,7 +289,7 @@ TEST_CASE("promise") {
|
||||
{
|
||||
bool call_fail_with_logic_error = false;
|
||||
pr::make_rejected_promise<int>(std::logic_error("hello fail"))
|
||||
.fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
.except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(call_fail_with_logic_error);
|
||||
@@ -297,7 +297,7 @@ TEST_CASE("promise") {
|
||||
{
|
||||
bool call_fail_with_logic_error = false;
|
||||
pr::make_rejected_promise(std::logic_error("hello fail"))
|
||||
.fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
.except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(call_fail_with_logic_error);
|
||||
@@ -313,7 +313,7 @@ TEST_CASE("promise") {
|
||||
throw std::logic_error("hello fail");
|
||||
}).then([¬_call_then_on_reject](){
|
||||
not_call_then_on_reject = false;
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(not_call_then_on_reject);
|
||||
@@ -328,7 +328,7 @@ TEST_CASE("promise") {
|
||||
throw std::logic_error("hello fail");
|
||||
}, [](std::exception_ptr){
|
||||
throw std::logic_error("hello fail2");
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail2_exception(e);
|
||||
});
|
||||
REQUIRE(not_call_then_on_reject);
|
||||
@@ -372,7 +372,7 @@ TEST_CASE("promise") {
|
||||
{
|
||||
auto pa = p.then([](int){
|
||||
throw std::logic_error("hello fail");
|
||||
}).fail([&pa_value](std::exception_ptr e){
|
||||
}).except([&pa_value](std::exception_ptr e){
|
||||
if ( check_hello_fail_exception(e) ) {
|
||||
pa_value = 84;
|
||||
}
|
||||
@@ -485,7 +485,7 @@ TEST_CASE("promise") {
|
||||
return p2;
|
||||
}).then([](int v2){
|
||||
(void)v2;
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
|
||||
@@ -502,7 +502,7 @@ TEST_CASE("promise") {
|
||||
}).then([](int v2){
|
||||
(void)v2;
|
||||
throw std::logic_error("hello fail");
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
|
||||
@@ -518,7 +518,7 @@ TEST_CASE("promise") {
|
||||
return p2;
|
||||
}).then([](int v2){
|
||||
(void)v2;
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
|
||||
@@ -534,7 +534,7 @@ TEST_CASE("promise") {
|
||||
return p2;
|
||||
}).then([](int v2){
|
||||
(void)v2;
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
|
||||
@@ -551,7 +551,7 @@ TEST_CASE("promise") {
|
||||
throw std::logic_error("hello fail");
|
||||
return p2;
|
||||
}).then([](){
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
|
||||
@@ -566,7 +566,7 @@ TEST_CASE("promise") {
|
||||
return p2;
|
||||
}).then([](){
|
||||
throw std::logic_error("hello fail");
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
|
||||
@@ -580,7 +580,7 @@ TEST_CASE("promise") {
|
||||
p1.then([&p2](){
|
||||
return p2;
|
||||
}).then([](){
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
|
||||
@@ -594,7 +594,7 @@ TEST_CASE("promise") {
|
||||
p1.then([&p2](){
|
||||
return p2;
|
||||
}).then([](){
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
|
||||
@@ -691,7 +691,7 @@ TEST_CASE("promise") {
|
||||
}).then([¬_call_then_on_reject](const std::vector<int>& c){
|
||||
(void)c;
|
||||
not_call_then_on_reject = false;
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(not_call_then_on_reject);
|
||||
@@ -711,7 +711,7 @@ TEST_CASE("promise") {
|
||||
}).then([¬_call_then_on_reject](const int& c){
|
||||
(void)c;
|
||||
not_call_then_on_reject = false;
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(not_call_then_on_reject);
|
||||
@@ -771,7 +771,7 @@ TEST_CASE("promise") {
|
||||
return std::vector<pr::promise<int>>{
|
||||
pr::make_rejected_promise<int>(std::logic_error("hello fail")),
|
||||
pr::make_resolved_promise(42)};
|
||||
}).fail([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
}).except([&call_fail_with_logic_error](std::exception_ptr e){
|
||||
call_fail_with_logic_error = check_hello_fail_exception(e);
|
||||
});
|
||||
REQUIRE(call_fail_with_logic_error);
|
||||
|
||||
Reference in New Issue
Block a user