Skip to content

Commit 1d44c39

Browse files
authored
improve (#537)
1 parent e7c3527 commit 1d44c39

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

include/cinatra/ylt/coro_io/coro_io.hpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,11 @@ inline async_simple::coro::Lazy<std::error_code> async_handshake(
260260
#endif
261261
class period_timer : public asio::steady_timer {
262262
public:
263+
using asio::steady_timer::steady_timer;
263264
template <typename T>
264265
period_timer(coro_io::ExecutorWrapper<T> *executor)
265266
: asio::steady_timer(executor->get_asio_executor()) {}
266-
template <typename executor_t, typename Rep, typename Period>
267-
period_timer(const executor_t &executor,
268-
const std::chrono::duration<Rep, Period> &timeout_duration)
269-
: asio::steady_timer(executor, timeout_duration) {}
267+
270268
async_simple::coro::Lazy<bool> async_await() noexcept {
271269
callback_awaitor<bool> awaitor;
272270

@@ -297,10 +295,10 @@ inline async_simple::coro::Lazy<void> sleep_for(const Duration &d) {
297295
}
298296
}
299297

300-
template <typename R, typename Func>
298+
template <typename R, typename Func, typename Executor>
301299
struct post_helper {
302300
void operator()(auto handler) const {
303-
asio::dispatch(e->get_asio_executor(), [this, handler]() {
301+
asio::dispatch(e, [this, handler]() {
304302
try {
305303
if constexpr (std::is_same_v<R, async_simple::Try<void>>) {
306304
func();
@@ -317,24 +315,30 @@ struct post_helper {
317315
}
318316
});
319317
}
320-
coro_io::ExecutorWrapper<> *e;
318+
Executor e;
321319
Func func;
322320
};
323321

324-
template <typename Func>
322+
template <typename Func, typename Executor>
325323
inline async_simple::coro::Lazy<
326324
async_simple::Try<typename util::function_traits<Func>::return_type>>
327-
post(Func func,
328-
coro_io::ExecutorWrapper<> *e = coro_io::get_global_block_executor()) {
325+
post(Func func, Executor executor) {
329326
using R =
330327
async_simple::Try<typename util::function_traits<Func>::return_type>;
331328

332329
callback_awaitor<R> awaitor;
333-
334-
post_helper<R, Func> helper{e, std::move(func)};
330+
post_helper<R, Func, Executor> helper{executor, std::move(func)};
335331
co_return co_await awaitor.await_resume(helper);
336332
}
337333

334+
template <typename Func>
335+
inline async_simple::coro::Lazy<
336+
async_simple::Try<typename util::function_traits<Func>::return_type>>
337+
post(Func func,
338+
coro_io::ExecutorWrapper<> *e = coro_io::get_global_block_executor()) {
339+
co_return co_await post(std::move(func), e->get_asio_executor());
340+
}
341+
338342
template <typename R>
339343
struct coro_channel
340344
: public asio::experimental::channel<void(std::error_code, R)> {

0 commit comments

Comments
 (0)