make_promise function also can create pending promises

This commit is contained in:
2018-12-09 22:45:05 +07:00
parent 1148557b2f
commit e1af6f13ac
2 changed files with 24 additions and 0 deletions

View File

@@ -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;

View File

@@ -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;