#include <Pt/System/Timer.h>
Interval timeout notifications. More...
Public Member Functions | |
| Timer () | |
| Default constructor. | |
| ~Timer () | |
| Destructor. | |
| EventLoop * | loop () |
| Returns the used event loop. | |
| void | setActive (EventLoop &loop) |
| Sets the used event loop. | |
| void | detach () |
| Detach from used event loop. | |
| bool | isStarted () const |
| Returs true if timer was started. | |
| std::size_t | interval () const |
| Returns the current timer interval in milliseconds. | |
| void | start (std::size_t interval) |
| Starts the timer. | |
| void | start (const Pt::Timespan &interval) |
| Starts the timer. | |
| void | stop () |
| Stops the timer. | |
| Signal & | timeout () |
| Notifies about interval timeouts. | |
| AsyncWait | waitAsync (std::size_t ms) |
| Start a one-shot timer delay as a C++20 awaitable. | |
Timer emits timeout at a fixed interval. It is not a Selectable. setActive() registers it with an EventLoop. start() begins the interval from the moment it is called. stop() ends it. timeout is not sent until the timer is registered and started.
The interval can be changed while the timer runs. start() again replaces it. detach() removes the timer from the loop. The destructor emits no timeout after that.
| Timer | ( | ) |
Constructs an inactive timer.
| ~Timer | ( | ) |
The destructor sends the destroyed signal.
| void start | ( | std::size_t | interval | ) |
Start a timer from the moment this method is called. The Timer needs to be registered with an event loop, otherwise the timeout signal will not be sent.
| interval | Timeout interval in milliseconds |
| void start | ( | const Pt::Timespan & | interval | ) |
Start a timer from the moment this method is called. The Timer needs to be registered with an event loop, otherwise the timeout signal will not be sent.
| void stop | ( | ) |
If the Timer is registered with an event loop, the timout signal will not be sent anymore.
| Signal & timeout | ( | ) |
This signal is sent if the interval time has expired.
| AsyncWait waitAsync | ( | std::size_t | ms | ) |
Returns an awaitable that suspends the coroutine until the timer fires after the specified duration. The timer is automatically stopped when the awaitable completes or is cancelled.
The Timer must be registered with an event loop via setActive() before awaiting.
| ms | Delay duration in milliseconds. |