tag::timer_example[]
| 11 | |
| 12 | // tag::timer_example[] |
| 13 | struct wait_op final : cobalt::op<system::error_code> // <1> |
| 14 | { |
| 15 | asio::steady_timer & tim; |
| 16 | wait_op(asio::steady_timer & tim) : tim(tim) {} |
| 17 | void ready(cobalt::handler<system::error_code> h ) override // <2> |
| 18 | { |
| 19 | if (tim.expiry() < std::chrono::steady_clock::now()) |
| 20 | h(system::error_code{}); |
| 21 | } |
| 22 | void initiate(cobalt::completion_handler<system::error_code> complete) override // <3> |
| 23 | { |
| 24 | tim.async_wait(std::move(complete)); |
| 25 | } |
| 26 | }; |
| 27 | |
| 28 | |
| 29 | cobalt::main co_main(int argc, char * argv[]) |