chore: Cancellable coroutines (#2180)

Add a wrap for `boost::asio::yield_context` to make async operations
cancellable by default. The API could be a bit adjusted when we start
switching our code to use it.
This commit is contained in:
Sergey Kuznetsov
2025-06-05 12:17:58 +01:00
committed by GitHub
parent 03070d7582
commit 4904c4b4d4
6 changed files with 491 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#pragma once
#include "util/Coroutine.hpp"
#include "util/LoggerFixtures.hpp"
#include <boost/asio/executor_work_guard.hpp>
@@ -79,6 +80,22 @@ private:
* This is meant to be used as a base for other fixtures.
*/
struct SyncAsioContextTest : virtual public NoLoggerFixture {
template <util::CoroutineFunction F>
void
runCoroutine(F&& f, bool allowMockLeak = false)
{
testing::MockFunction<void()> call;
if (allowMockLeak)
testing::Mock::AllowLeak(&call);
util::Coroutine::spawnNew(ctx_, [&, _ = boost::asio::make_work_guard(ctx_)](util::Coroutine& coroutine) {
f(coroutine);
call.Call();
});
EXPECT_CALL(call, Call());
runContext();
}
template <typename F>
void
runSpawn(F&& f, bool allowMockLeak = false)