Skip to content

Commit b497050

Browse files
committed
clean-up the test
1 parent de0579e commit b497050

File tree

1 file changed

+18
-41
lines changed

1 file changed

+18
-41
lines changed

tests/beman/execution/issue-174.test.cpp

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,30 @@
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
#include <beman/execution/execution.hpp>
5-
#include <iostream>
6-
#include <format>
75
#include <thread>
6+
#include <utility>
87

98
namespace ex = beman::execution;
109

1110
namespace {
12-
std::thread::id main_thread_id = std::this_thread::get_id();
13-
14-
template<typename... Args>
15-
void debug(std::format_string<Args...> fmt, Args&&... args) {
16-
auto thread_id = std::this_thread::get_id();
17-
auto thread_name = thread_id == main_thread_id ? "main" : (std::stringstream{} << thread_id).str();
18-
std::clog << std::format("[thread-{}] {}\n", thread_name, std::format(fmt, std::forward<Args>(args)...));
19-
}
20-
}
21-
22-
int main() {
23-
ex::run_loop ex_context1;
24-
std::thread thread1{
25-
[&ex_context1] {
26-
debug("ex_context1 run...");
27-
ex_context1.run();
28-
}
29-
};
30-
31-
ex::run_loop ex_context2;
32-
std::thread thread2{
33-
[&ex_context2] {
34-
debug("ex_context2 run...");
35-
ex_context2.run();
11+
struct thread_loop: ex::run_loop {
12+
std::thread thread{[this] { this->run(); }};
13+
~thread_loop() {
14+
this->finish();
15+
this->thread.join();
3616
}
3717
};
18+
}
3819

39-
ex::sender auto snd = ex::just() | ex::then([] {
40-
debug("#1");
41-
}) | ex::continues_on(ex_context1.get_scheduler()) | ex::then([] {
42-
debug("#2");
43-
}) | ex::continues_on(ex_context2.get_scheduler()) | ex::then([] {
44-
debug("#3");
45-
});
46-
47-
ex::sync_wait(snd);
48-
49-
ex_context1.finish();
50-
ex_context2.finish();
51-
52-
thread2.join();
53-
thread1.join();
20+
int main() {
21+
thread_loop ex_context1;
22+
thread_loop ex_context2;
23+
24+
ex::sync_wait(
25+
ex::just()
26+
| ex::then([] { })
27+
| ex::continues_on(ex_context1.get_scheduler())
28+
| ex::then([] { })
29+
| ex::continues_on(ex_context2.get_scheduler()) | ex::then([] {})
30+
);
5431
}

0 commit comments

Comments
 (0)