| 31 | }; |
| 32 | |
| 33 | int 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 | } |