Updated coroutine test case with local class (#384)

This commit is contained in:
Bartek Kryza 2025-02-05 13:22:47 +01:00
parent 32ab85a6c4
commit 66038482f5
No known key found for this signature in database
GPG Key ID: 241B25F44E85B4D7
2 changed files with 17 additions and 16 deletions

View File

@ -4,21 +4,22 @@
#include <thread>
namespace clanguml::t20071 {
struct awaitable_on_thread {
std::thread *p_out;
bool await_ready() { return false; }
void await_suspend(std::coroutine_handle<> h)
{
auto &out = *p_out;
if (out.joinable())
throw std::runtime_error("Output thread parameter not empty");
out = std::thread([h] { h.resume(); });
}
void await_resume() { }
};
auto switch_to_new_thread(std::thread &out)
{
struct awaitable_on_thread {
std::thread *p_out;
bool await_ready() { return false; }
void await_suspend(std::coroutine_handle<> h)
{
auto &out = *p_out;
if (out.joinable())
throw std::runtime_error("Output thread parameter not empty");
out = std::thread([h] { h.resume(); });
}
void await_resume() { }
};
return awaitable_on_thread{&out};
}

View File

@ -34,15 +34,15 @@ TEST_CASE("t20071")
{"t20071.cc", "t20071.cc",
"switch_to_new_thread(std::thread &)"}, //
#if LLVM_VERSION_MAJOR == 14 || LLVM_VERSION_MAJOR == 15
{"t20071.cc", "t20071.cc",
"struct clanguml::t20071::awaitable_on_thread",
{"t20071.cc", "t20071.cc", "struct awaitable_on_thread",
Response{}}, //
#else
{"t20071.cc", "t20071.cc", "awaitable_on_thread",
Response{}}, //
#endif
{"t20071.cc", "awaitable_on_thread", "await_resume()",
CoAwait{}} //
{"t20071.cc",
"switch_to_new_thread(std::thread &)::awaitable_on_thread",
"await_resume()", CoAwait{}} //
}));
});
}