MCPcopy Create free account
hub / github.com/boostorg/asio / cancel_after_function_object_test

Function cancel_after_function_object_test

test/cancel_after.cpp:34–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34void cancel_after_function_object_test()
35{
36 io_context ioc;
37 int count = 0;
38
39 steady_timer t(ioc, chronons::milliseconds(100));
40 t.async_wait(
41 cancel_after(chronons::seconds(5),
42 bindns::bind(&increment_on_cancel,
43 &count, bindns::placeholders::_1)));
44
45 ioc.run();
46
47 BOOST_ASIO_CHECK(count == 0);
48
49 t.expires_after(chronons::seconds(5));
50 t.async_wait(
51 cancel_after(chronons::milliseconds(100),
52 bindns::bind(&increment_on_cancel,
53 &count, bindns::placeholders::_1)));
54
55 ioc.restart();
56 ioc.run();
57
58 BOOST_ASIO_CHECK(count == 1);
59
60 t.expires_after(chronons::milliseconds(100));
61 t.async_wait(
62 cancel_after(chronons::seconds(5),
63 cancel_after(chronons::seconds(10),
64 bindns::bind(&increment_on_cancel,
65 &count, bindns::placeholders::_1))));
66
67 ioc.restart();
68 ioc.run();
69
70 BOOST_ASIO_CHECK(count == 1);
71
72 t.expires_after(chronons::seconds(5));
73 t.async_wait(
74 cancel_after(chronons::milliseconds(100),
75 cancel_after(chronons::seconds(10),
76 bindns::bind(&increment_on_cancel,
77 &count, bindns::placeholders::_1))));
78
79 ioc.restart();
80 ioc.run();
81
82 BOOST_ASIO_CHECK(count == 2);
83
84 t.expires_after(chronons::seconds(5));
85 t.async_wait(
86 cancel_after(chronons::seconds(10),
87 cancel_after(chronons::milliseconds(100),
88 bindns::bind(&increment_on_cancel,
89 &count, bindns::placeholders::_1))));
90
91 ioc.restart();

Callers

nothing calls this directly

Calls 5

restartMethod · 0.80
bindFunction · 0.50
async_waitMethod · 0.45
runMethod · 0.45
expires_afterMethod · 0.45

Tested by

no test coverage detected