-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathintro-2-hello-async.cpp
More file actions
39 lines (33 loc) · 1.33 KB
/
intro-2-hello-async.cpp
File metadata and controls
39 lines (33 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// examples/intro-2-hello-async.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <beman/execution/execution.hpp>
#include "intro-timer.hpp"
#include <chrono>
#include <iostream>
#include <string>
#include <tuple>
namespace ex = ::beman::execution;
using namespace std::string_literals;
using namespace std::chrono_literals;
// ----------------------------------------------------------------------------
// Please see the explanation in docs/intro-examples.md for an explanation.
int main() {
std::cout << std::unitbuf;
intro::timer timer;
// clang-format off
auto [result] = ex::sync_wait(
ex::when_all(
timer.run(),
ex::when_all(
timer.resume_after(3s)
| ex::then([] { std::cout << "h\n"; return std::string("hello"); }),
timer.resume_after(1s)
| ex::then([] { std::cout << ",\n"; return std::string(", "); }),
timer.resume_after(2s)
| ex::then([] { std::cout << "w\n"; return std::string("world"); })
) | ex::then([](auto const& s1, auto const& s2, auto const& s3) { return s1 + s2 + s3; })
)
).value_or(std::tuple(std::string("")));
// clang-format on
std::cout << result << "\n";
}