This commit is contained in:
2019-10-02 20:29:42 +07:00
parent fdf7f489ef
commit dd92ea6fb1
2 changed files with 41 additions and 3 deletions

View File

@@ -7,6 +7,7 @@
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <array>
#include <thread>
#include <numeric>
#include <cstring>
@@ -693,6 +694,22 @@ TEST_CASE("promise") {
REQUIRE(call_then_only_once == 1);
}
{
auto p1 = pr::promise<int>();
auto p2 = pr::promise<int>();
int call_then_only_once = 0;
pr::make_all_promise(std::array<pr::promise<int>, 2>{p1, p2})
.then([&call_then_only_once](const std::vector<int>& c){
(void)c;
++call_then_only_once;
});
p1.resolve(1);
p2.resolve(2);
REQUIRE(call_then_only_once == 1);
}
{
class o_t {
public:
@@ -749,6 +766,26 @@ TEST_CASE("promise") {
REQUIRE(check_42_int == 42);
REQUIRE(call_then_only_once == 1);
}
{
auto p1 = pr::promise<int>();
auto p2 = pr::promise<int>();
int check_42_int = 0;
int call_then_only_once = 0;
pr::make_race_promise(std::array<pr::promise<int>,2>{p1, p2})
.then([&check_42_int, &call_then_only_once](const int& v){
check_42_int = v;
++call_then_only_once;
});
p2.resolve(42);
REQUIRE(check_42_int == 42);
REQUIRE(call_then_only_once == 1);
p1.resolve(84);
REQUIRE(check_42_int == 42);
REQUIRE(call_then_only_once == 1);
}
{
class o_t {
public: