Skip to content

Commit

Permalink
[coro_rpc] allow user executor customize post op (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle authored Mar 22, 2023
1 parent a4181ba commit 69235e3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions include/asio_util/asio_coro_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,25 @@ class ExecutorWrapper : public async_simple::Executor {
using context_t = std::remove_cvref_t<decltype(executor_.context())>;

virtual bool schedule(Func func) override {
asio::post(executor_, std::move(func));
if constexpr (requires(ExecutorImpl e) { e.post(std::move(func)); }) {
executor_.post(std::move(func));
}
else {
asio::post(executor_, std::move(func));
}

return true;
}

virtual bool checkin(Func func, void *ctx) override {
using context_t = std::remove_cvref_t<decltype(executor_.context())>;
asio::post(*(context_t *)ctx, func);
auto &executor = *(context_t *)ctx;
if constexpr (requires(ExecutorImpl e) { e.post(std::move(func)); }) {
executor.post(std::move(func));
}
else {
asio::post(executor, std::move(func));
}
return true;
}
virtual void *checkout() override { return &executor_.context(); }
Expand Down

0 comments on commit 69235e3

Please sign in to comment.