38#include <gtest/gtest.h>
58 return std::async(std::launch::async, [value] {
return value; });
64 return std::async(std::launch::async, [value,
delay_ms] {
65 std::this_thread::sleep_for(std::chrono::milliseconds(
delay_ms));
73 return std::async(std::launch::async, [] {});
79 return std::async(std::launch::async, [&counter] { ++counter; });
85 return std::async(std::launch::async, []() ->
int {
86 throw std::runtime_error(
"Test exception");
119 for (
int i = 1; i <= 5; ++i)
164 EXPECT_EQ(it.get_curr(), 100); it.next();
165 EXPECT_EQ(it.get_curr(), 200); it.next();
177 futures.
append(std::async(std::launch::async, [] {
return 42; }));
178 futures.
append(std::async(std::launch::async, [] {
return 43; }));
209 std::atomic<int> counter{0};
212 for (
int i = 0; i < 5; ++i)
223 std::atomic<int> counter{0};
227 futures.
append(std::async(std::launch::async, [&counter] { ++counter; }));
228 futures.
append(std::async(std::launch::async, [&counter] { ++counter; }));
256 throw std::logic_error(
"Void exception");
279 std::this_thread::sleep_for(std::chrono::milliseconds(50));
303 std::this_thread::sleep_for(std::chrono::milliseconds(50));
324 for (
int i = 0; i < 5; ++i)
328 std::this_thread::sleep_for(std::chrono::milliseconds(50));
339 for (
int i = 0; i < 3; ++i)
357 std::this_thread::sleep_for(std::chrono::milliseconds(50));
374 futures.
append(std::async(std::launch::async, [] {
return std::string(
"hello"); }));
375 futures.
append(std::async(std::launch::async, [] {
return std::string(
"world"); }));
382 EXPECT_EQ(it.get_curr(),
"hello"); it.next();
389 futures.
append(std::async(std::launch::async, [] {
return 3.14; }));
390 futures.
append(std::async(std::launch::async, [] {
return 2.71; }));
405 return std::vector<int>{1, 2, 3};
408 return std::vector<int>{4, 5};
428 constexpr int N = 100;
430 for (
int i = 0; i <
N; ++i)
448 std::atomic<int> counter{0};
450 constexpr int N = 100;
452 for (
int i = 0; i <
N; ++i)
490 futures.
append(std::async(std::launch::async, [] {
return std::string(); }));
504 ::testing::InitGoogleTest(&
argc,
argv);
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
T & get_first() const
Return the first item of the list.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
static std::future< void > make_void_future()
static std::future< int > make_int_future(int value)
static std::future< int > make_delayed_future(int value, int delay_ms)
static std::future< void > make_void_future_with_effect(std::atomic< int > &counter)
static std::future< int > make_failing_future()
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Utility functions for working with std::future collections.
TEST_F(FutureUtilsTest, GetFuturesEmptyList)
Main namespace for Aleph-w library functions.
size_t count_ready(DynList< std::future< T > > &future_list)
Count how many futures are ready.
DynList< T > get_futures(DynList< std::future< T > > &future_list)
Collect results from a list of futures.
bool all_ready(DynList< std::future< T > > &future_list)
Check if all futures in a list are ready.
DynList< T > maps(const C &c, Op op)
Classic map operation.
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.