3#include <condition_variable>
7#include <nlohmann/json.hpp>
25 : strand_(std::move(strand)) {
46 asio::post(strand_, [
this, result = std::move(result)]()
mutable {
48 result_ = std::move(result);
52 std::lock_guard<std::mutex> lock(mutex_);
53 ready_cv_.notify_all();
64 void Cancel(
int code,
const std::string& message) {
66 nlohmann::json error = {{
"error", {{
"code", code}, {
"message", message}}}};
79 auto GetResult() -> asio::awaitable<nlohmann::json> {
87 auto executor =
co_await asio::this_coro::executor;
88 asio::steady_timer timer(executor, std::chrono::milliseconds(10));
91 co_await timer.async_wait(asio::use_awaitable);
92 timer.expires_after(std::chrono::milliseconds(10));
119 asio::strand<asio::any_io_executor> strand_;
122 nlohmann::json result_;
134 std::condition_variable ready_cv_;
A class representing a pending RPC request.
PendingRequest(const PendingRequest &)=delete
auto operator=(PendingRequest &&) -> PendingRequest &=delete
bool IsReady() const
Check if the request is ready.
bool HasError() const
Check if the request has an error.
~PendingRequest()=default
Destructor.
auto operator=(const PendingRequest &) -> PendingRequest &=delete
void SetResult(nlohmann::json result)
Sets the result of the request.
auto GetResult() -> asio::awaitable< nlohmann::json >
Get the result asynchronously.
PendingRequest(asio::strand< asio::any_io_executor > strand)
Construct a new Pending Request object.
PendingRequest(PendingRequest &&)=delete
void Cancel(int code, const std::string &message)
Cancels the request with an error.