Skip to content

Commit

Permalink
turn Call into struct
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Sep 18, 2024
1 parent 3da64d2 commit bafca5e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions silkworm/infra/grpc/client/unary_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,37 @@ template <
class UnaryRpc<Async> {
private:
template <typename Dispatcher>
struct Call {
UnaryRpc& self;
const Request& request;
[[no_unique_address]] Dispatcher dispatcher;

class Call {
public:
Call(UnaryRpc& self, const Request& request, Dispatcher dispatcher = {})
: self_{self}, request_{request}, dispatcher_{std::move(dispatcher)} {}

template <typename Op>
void operator()(Op& op) {
SILK_TRACE << "UnaryRpc::initiate " << this;
self.reader_ = agrpc::request(Async, self.stub_, self.context_, request, self.grpc_context_);
agrpc::finish(self.reader_, self.reply_, self.status_, boost::asio::bind_executor(self.grpc_context_, std::move(op)));
self_.reader_ = agrpc::request(Async, self_.stub_, self_.context_, request_, self_.grpc_context_);
agrpc::finish(self_.reader_, self_.reply_, self_.status_, boost::asio::bind_executor(self_.grpc_context_, std::move(op)));
}

template <typename Op>
void operator()(Op& op, bool /*ok*/) {
dispatcher.dispatch(std::move(op), detail::DoneTag{});
dispatcher_.dispatch(std::move(op), detail::DoneTag{});
}

template <typename Op>
void operator()(Op& op, detail::DoneTag) {
SILK_DEBUG << "UnaryRpc::completed " << self.status_;
if (self.status_.ok()) {
op.complete({}, std::move(self.reply_));
SILK_DEBUG << "UnaryRpc::completed " << self_.status_;
if (self_.status_.ok()) {
op.complete({}, std::move(self_.reply_));
} else {
op.complete(make_error_code(self.status_.error_code(), self.status_.error_message()), {});
op.complete(make_error_code(self_.status_.error_code(), self_.status_.error_message()), {});
}
}

private:
UnaryRpc& self_;
const Request& request_;
[[no_unique_address]] Dispatcher dispatcher_;
};

public:
Expand Down

0 comments on commit bafca5e

Please sign in to comment.