Skip to content

Commit 53666c6

Browse files
committed
replace call_later call in call_at with other code
1 parent 570a387 commit 53666c6

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/eventloop.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,26 @@ void event_loop::_sock_accept(event_loop& loop, object fut, object sock)
9898

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

108108
void event_loop::call_at(double when, object f)
109109
{
110110
double diff = when - time();
111111
if (diff > 0)
112-
return call_later(diff, f);
113-
return call_soon(f);
112+
{
113+
auto p_timer = std::make_shared<boost::asio::steady_timer>(
114+
_strand.context(),
115+
std::chrono::nanoseconds(int64_t(diff * 1e9)));
116+
p_timer->async_wait(boost::asio::bind_executor(_strand,
117+
[f, p_timer, this] (const boost::system::error_code& ec) {f();}));
118+
return;
119+
}
120+
call_soon(f);
114121
}
115122

116123
object event_loop::sock_recv(object sock, size_t nbytes)

0 commit comments

Comments
 (0)