mirror of
https://github.com/BlackMATov/promise.hpp.git
synced 2025-12-13 03:46:29 +07:00
fix #27 issue
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user