Skip to content

Commit

Permalink
Previous function return arg ignoring fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanPinezhaninov committed Dec 2, 2023
1 parent c18d05b commit c93baa2
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 7 deletions.
10 changes: 5 additions & 5 deletions include/async_promise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ class promise
typename = typename std::enable_if<!std::is_void<FuncResult>::value>::type>
promise<Result> all(Container<Func, Allocator> funcs) const
{
using task = internal::all_task_void<Result, void, Container, Func, Allocator>;
using task = internal::all_task_void<Result, T, Container, Func, Allocator>;
return promise<Result>{std::make_shared<task>(m_task, std::move(funcs))};
}

Expand Down Expand Up @@ -1778,7 +1778,7 @@ class promise
typename = typename std::true_type::type>
promise<Result> all_settled(Container<Func, Allocator> funcs) const
{
using task = internal::all_settled_task_void<Result, void, void, Container, Func, Allocator>;
using task = internal::all_settled_task_void<Result, T, void, Container, Func, Allocator>;
return promise<Result>{std::make_shared<task>(m_task, std::move(funcs))};
}

Expand Down Expand Up @@ -1814,7 +1814,7 @@ class promise
typename = typename std::enable_if<!std::is_void<FuncResult>::value>::type>
promise<Result> all_settled(Container<Func, Allocator> funcs) const
{
using task = internal::all_settled_task_void<Result, void, FuncResult, Container, Func, Allocator>;
using task = internal::all_settled_task_void<Result, T, FuncResult, Container, Func, Allocator>;
return promise<Result>{std::make_shared<task>(m_task, std::move(funcs))};
}

Expand Down Expand Up @@ -1845,7 +1845,7 @@ class promise
typename Result = typename std::result_of<Func()>::type>
promise<Result> any(Container<Func, Allocator> funcs) const
{
using task = internal::any_task_void<Result, void, Container, Func, Allocator>;
using task = internal::any_task_void<Result, T, Container, Func, Allocator>;
return promise<Result>{std::make_shared<task>(m_task, std::move(funcs))};
}

Expand Down Expand Up @@ -1876,7 +1876,7 @@ class promise
typename Result = typename std::result_of<Func()>::type>
promise<Result> race(Container<Func, Allocator> funcs) const
{
using task = internal::race_task_void<Result, void, Container, Func, Allocator>;
using task = internal::race_task_void<Result, T, Container, Func, Allocator>;
return promise<Result>{std::make_shared<task>(m_task, std::move(funcs))};
}

Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ set(SOURCES
src/funcs.cpp
src/initial.cpp
src/race.cpp
src/reject.cpp
src/resolve.cpp
src/static_all_settled.cpp
src/static_all.cpp
src/static_any.cpp
src/static_race.cpp
src/static_reject.cpp
src/static_resolve.cpp
src/then.cpp
)

Expand Down
19 changes: 19 additions & 0 deletions tests/src/all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ TEST_CASE("All string void", "[all]")
}


TEST_CASE("All string void ignore arg", "[all]")
{
std::vector<std::string(*)()> funcs
{
[] () { return std::string{str}; },
[] () { return std::string{str}; },
};

auto future = async::static_promise<std::string>::resolve(str).all(funcs).run();

std::vector<std::string> res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE(res.size() == funcs.size());

for (const auto& val : res)
REQUIRE(val == str);
}


TEST_CASE("All error string void", "[all]")
{
std::vector<std::string(*)()> funcs
Expand Down
21 changes: 21 additions & 0 deletions tests/src/all_settled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,27 @@ TEST_CASE("All settled string void", "[all_settled]")
}


TEST_CASE("All settled string void ignore arg", "[all_settled]")
{
std::vector<std::string(*)()> funcs
{
[] () { return std::string{str}; },
[] () { return std::string{str}; },
};

auto future = async::static_promise<std::string>::resolve(str).all_settled(funcs).run();

std::vector<async::settled<std::string>> res;
REQUIRE_NOTHROW(res = future.get());

REQUIRE(res.size() == funcs.size());
REQUIRE(res.front().type == async::settle_type::resolved);
REQUIRE(res.front().result == str);
REQUIRE(res.back().type == async::settle_type::resolved);
REQUIRE(res.back().result == str);
}


TEST_CASE("All settled error string void", "[all_settled]")
{
std::vector<std::string(*)()> funcs
Expand Down
16 changes: 16 additions & 0 deletions tests/src/any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ TEST_CASE("Any string void", "[any]")
}


TEST_CASE("Any string void ignore arg", "[any]")
{
std::vector<std::string(*)()> funcs
{
[] () { return std::string{str}; },
[] () { return std::string{str}; },
};

auto future = async::static_promise<std::string>::resolve(str).any(funcs).run();

std::string res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE(res == str);
}


TEST_CASE("Any error string void", "[any]")
{
std::vector<std::string(*)()> funcs
Expand Down
16 changes: 16 additions & 0 deletions tests/src/race.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ TEST_CASE("Race string void", "[race]")
}


TEST_CASE("Race string void ignore arg", "[race]")
{
std::vector<std::string(*)()> str_void
{
[] () { return std::string{str}; },
[] () { return std::string{str}; },
};

auto future = async::static_promise<std::string>::resolve(str).race(str_void).run();

std::string res;
REQUIRE_NOTHROW(res = future.get());
REQUIRE(res == str);
}


TEST_CASE("Race error won string void", "[race]")
{
std::vector<std::string(*)()> str_void
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit c93baa2

Please sign in to comment.