qb
2.0.0.0
C++17 Actor Framework
|
Utility class to execute a function after a specified timeout using the event loop. More...
#include <io.h>
Public Member Functions | |
Timeout (_Func &&func, double timeout=0.) | |
Constructor that schedules a function to be called after a timeout. | |
void | on (event::timer const &) const |
Timer event handler called when the timeout expires. | |
Public Member Functions inherited from qb::io::async::with_timeout< Timeout< _Func > > | |
with_timeout (ev_tstamp timeout=3) | |
Constructor that initializes the timeout. | |
void | updateTimeout () noexcept |
Updates the last activity timestamp to the current event loop time. | |
void | setTimeout (ev_tstamp timeout) noexcept |
Sets a new timeout value and restarts the timer. | |
auto | getTimeout () const noexcept |
Gets the current configured timeout value. |
Additional Inherited Members | |
Protected Member Functions inherited from qb::io::async::base< with_timeout< Timeout< _Func > >, event::timer > | |
base () | |
Constructor that registers the event watcher with the current listener. | |
~base () | |
Destructor that unregisters the event watcher. | |
Protected Attributes inherited from qb::io::async::base< with_timeout< Timeout< _Func > >, event::timer > | |
event::timer & | _async_event |
Reference to the registered libev-based event watcher. |
Utility class to execute a function after a specified timeout using the event loop.
This class inherits from with_timeout to schedule a one-shot execution of a provided callable (function, lambda, functor). It automatically manages its own lifetime, deleting itself after the function is executed or if the timeout is explicitly cancelled.
_Func | The function type (or callable object type) to execute after the timeout. |
|
inline |
Constructor that schedules a function to be called after a timeout.
func | The function to execute. It will be moved into the Timeout object. |
timeout | Timeout duration in seconds before execution. If 0.0 or less, the function is executed immediately (or in the next loop iteration, depending on with_timeout behavior) and this Timeout object is deleted. |
|
inline |
Timer event handler called when the timeout expires.
event | The event::timer that triggered (marked as unused here as specific timer details are not needed). |
Executes the stored function _func and then deletes this Timeout object, ensuring one-shot execution and automatic cleanup.