mirror of
https://github.com/BlackMATov/promise.hpp.git
synced 2025-12-15 04:25:28 +07:00
make_promise function also can create pending promises
This commit is contained in:
@@ -656,6 +656,11 @@ namespace promise_hpp
|
||||
// make_promise
|
||||
//
|
||||
|
||||
template < typename R >
|
||||
promise<R> make_promise() {
|
||||
return promise<R>();
|
||||
}
|
||||
|
||||
template < typename R, typename F >
|
||||
promise<R> make_promise(F&& f) {
|
||||
promise<R> result;
|
||||
|
||||
19
tests.cpp
19
tests.cpp
@@ -426,6 +426,25 @@ TEST_CASE("promise") {
|
||||
REQUIRE(check_84_int == 84);
|
||||
}
|
||||
}
|
||||
SECTION("lazy_chaining") {
|
||||
{
|
||||
int check_84_int = 0;
|
||||
auto p1 = pr::make_promise<int>();
|
||||
auto p2 = pr::make_promise<int>();
|
||||
|
||||
p1.then([&p2](int v){
|
||||
return p2;
|
||||
}).then([&check_84_int](int v2){
|
||||
check_84_int = v2;
|
||||
});
|
||||
|
||||
REQUIRE(check_84_int == 0);
|
||||
p1.resolve(42);
|
||||
REQUIRE(check_84_int == 0);
|
||||
p2.resolve(84);
|
||||
REQUIRE(check_84_int == 84);
|
||||
}
|
||||
}
|
||||
SECTION("typed_chaining_fails") {
|
||||
{
|
||||
bool call_fail_with_logic_error = false;
|
||||
|
||||
Reference in New Issue
Block a user