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:
@@ -1111,7 +1111,7 @@ namespace promise_hpp
|
||||
}
|
||||
|
||||
template < typename Iter
|
||||
, typename SubPromise = typename Iter::value_type
|
||||
, typename SubPromise = typename std::iterator_traits<Iter>::value_type
|
||||
, typename SubPromiseResult = typename SubPromise::value_type
|
||||
, typename ResultPromiseValueType = std::vector<SubPromiseResult> >
|
||||
promise<ResultPromiseValueType>
|
||||
@@ -1149,9 +1149,10 @@ namespace promise_hpp
|
||||
//
|
||||
|
||||
template < typename Iter
|
||||
, typename SubPromise = typename Iter::value_type
|
||||
, typename SubPromise = typename std::iterator_traits<Iter>::value_type
|
||||
, typename SubPromiseResult = typename SubPromise::value_type >
|
||||
auto make_race_promise(Iter begin, Iter end) {
|
||||
promise<SubPromiseResult>
|
||||
make_race_promise(Iter begin, Iter end) {
|
||||
if ( begin == end ) {
|
||||
throw std::logic_error("at least one input promise must be provided for make_race_promise");
|
||||
}
|
||||
|
||||
@@ -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