23#include <gtest/gtest.h>
25using namespace std::chrono_literals;
32 EXPECT_TRUE(f.Ready());
36 EXPECT_EQ(std::move(result).Ok(), 42);
47 std::cout <<
"Async result from thread pool: " << std::move(result).Ok() << std::endl;
50 EXPECT_TRUE(!f.Valid());
63 auto process = [](
int r) {
71 EXPECT_TRUE(!f1.
Valid());
73 std::cout <<
"process(compute()) -> " << std::move(f2).Get().Ok() << std::endl;
84 auto first = []() ->
int {
88 auto second = [](
int r) {
92 auto third = [](
int r) {
96 auto fourth = [](
int r) {
97 return std::to_string(r);
101 std::cout <<
"Pipeline result: <" << std::move(r).Ok() <<
">" << std::endl;
105 yaclib::Run(tp, first).Then(second).Then(third).Then(fourth).Detach(last);
139 return calculator.
Double(r);
145 std::cout <<
"Result: " << std::move(r).Ok() << std::endl;
163 std::move(p).Set(42);
167 std::cout <<
"Hello from the second thread pool!";
184 auto second = [](
int r) {
188 auto third = [](
int r) {
193 .Then(*strand, second)
196 std::cout <<
"Final result: " << std::move(r).Value() << std::endl;
yaclib::FutureOn< int > Increment(int value)
CalculatorService(yaclib::IExecutorPtr e)
yaclib::FutureOn< int > Double(int value)
TODO(kononovk) Doxygen docs.
bool Valid() const &noexcept
Check if this Future has Promise.
Provides a mechanism to access the result of async operations.
auto Then(Func &&f) &&
Attach the continuation func to *this.
Encapsulated return value from caller.
auto Run(Func &&f)
Execute Callable func on Inline executor.
IExecutorPtr MakeStrand(IExecutorPtr e)
Strand is the asynchronous analogue of a mutex.
Contract< V, E > MakeContract()
Creates related future and promise.
TEST(Example, HelloWorld)