mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user