MCPcopy Create free account
hub / github.com/chronoxor/CppServer / main

Function main

examples/asio_timer.cpp:33–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31};
32
33int main(int argc, char** argv)
34{
35 // Create a new Asio service
36 auto service = std::make_shared<AsioService>();
37
38 // Start the Asio service
39 std::cout << "Asio service starting...";
40 service->Start();
41 std::cout << "Done!" << std::endl;
42
43 // Create a new Asio timer
44 auto timer = std::make_shared<AsioTimer>(service);
45
46 // Setup and synchronously wait for the timer
47 timer->Setup(CppCommon::UtcTime() + CppCommon::Timespan::seconds(1));
48 timer->WaitSync();
49
50 // Setup and asynchronously wait for the timer
51 timer->Setup(CppCommon::Timespan::seconds(1));
52 timer->WaitAsync();
53
54 // Wait for a while...
55 CppCommon::Thread::Sleep(2000);
56
57 // Setup and asynchronously wait for the timer
58 timer->Setup(CppCommon::Timespan::seconds(1));
59 timer->WaitAsync();
60
61 // Wait for a while...
62 CppCommon::Thread::Sleep(500);
63
64 // Cancel the timer
65 timer->Cancel();
66
67 // Wait for a while...
68 CppCommon::Thread::Sleep(500);
69
70 // Stop the Asio service
71 std::cout << "Asio service stopping...";
72 service->Stop();
73 std::cout << "Done!" << std::endl;
74
75 return 0;
76}

Callers

nothing calls this directly

Calls 6

SetupMethod · 0.80
WaitSyncMethod · 0.80
WaitAsyncMethod · 0.80
StartMethod · 0.45
CancelMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected