Skip to content

Commit c03428e

Browse files
committed
Boost 1.71.0: src/async_sleep.h
1 parent f9455dd commit c03428e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/async_sleep.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,27 @@ bool async_sleep( const asio::executor& exec
3030
return true;
3131
}
3232

33+
inline
34+
bool async_sleep( asio::io_context& ctx
35+
, asio::steady_timer::duration duration
36+
, Signal<void()>& cancel
37+
, asio::yield_context yield)
38+
{
39+
asio::steady_timer timer(ctx);
40+
timer.expires_from_now(duration);
41+
sys::error_code ec;
42+
43+
auto stop_timer = cancel.connect([&timer] {
44+
timer.cancel();
45+
});
46+
47+
timer.async_wait(yield[ec]);
48+
49+
if (ec || cancel) {
50+
return false;
51+
}
52+
53+
return true;
54+
}
55+
3356
} // ouinet namespace

0 commit comments

Comments
 (0)