Skip to content

Commit

Permalink
replace call_later call in call_at with other code
Browse files Browse the repository at this point in the history
  • Loading branch information
philoinovsky committed Jul 11, 2021
1 parent 570a387 commit 53666c6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/eventloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,26 @@ void event_loop::_sock_accept(event_loop& loop, object fut, object sock)

void event_loop::call_later(double delay, object f)
{
auto p_timer = std::make_shared<boost::asio::steady_timer>(_strand.context(),
std::chrono::nanoseconds(int64_t(delay * 1e9)));
p_timer->async_wait(boost::asio::bind_executor(
_strand,
auto p_timer = std::make_shared<boost::asio::steady_timer>(
_strand.context(),
std::chrono::nanoseconds(int64_t(delay * 1e9)));
p_timer->async_wait(boost::asio::bind_executor(_strand,
[f, p_timer, this] (const boost::system::error_code& ec) {f();}));
}

void event_loop::call_at(double when, object f)
{
double diff = when - time();
if (diff > 0)
return call_later(diff, f);
return call_soon(f);
{
auto p_timer = std::make_shared<boost::asio::steady_timer>(
_strand.context(),
std::chrono::nanoseconds(int64_t(diff * 1e9)));
p_timer->async_wait(boost::asio::bind_executor(_strand,
[f, p_timer, this] (const boost::system::error_code& ec) {f();}));
return;
}
call_soon(f);
}

object event_loop::sock_recv(object sock, size_t nbytes)
Expand Down

0 comments on commit 53666c6

Please sign in to comment.