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, [] {});
85 return std::async(std::launch::async, []() ->
int {
86 throw std::runtime_error(
"Test exception");
119 for (
int i = 1; i <= 5; ++i)
140 futures.append(make_int_future(2));
141 futures.append(make_int_future(3));
155 futures.append(make_delayed_future(200, 10));
156 futures.append(make_delayed_future(300, 30));
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; }));
212 for (
int i = 0; i < 5; ++i)
245 futures.append(make_failing_future());
246 futures.append(make_int_future(3));
255 futures.append(std::async(std::launch::async, [] {
256 throw std::logic_error(
"Void exception");
276 futures.append(make_int_future(2));
279 std::this_thread::sleep_for(std::chrono::milliseconds(50));
300 futures.append(make_delayed_future(2, 500));
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)
353 futures.append(make_int_future(2));
354 futures.append(make_delayed_future(3, 500));
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};
407 futures.append(std::async(std::launch::async, [] {
408 return std::vector<int>{4, 5};
428 constexpr int N = 100;
430 for (
int i = 0; i <
N; ++i)
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)
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()
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.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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.