qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::async::Timeout< _Func > Class Template Reference

Utility class to execute a function after a specified timeout using the event loop. More...

#include <io.h>

Inheritance diagram for qb::io::async::Timeout< _Func >:
Collaboration diagram for qb::io::async::Timeout< _Func >:

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.

Detailed Description

template<typename _Func>
class qb::io::async::Timeout< _Func >

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.

Template Parameters
_FuncThe function type (or callable object type) to execute after the timeout.

Constructor & Destructor Documentation

◆ Timeout()

template<typename _Func>
qb::io::async::Timeout< _Func >::Timeout ( _Func && func,
double timeout = 0. )
inline

Constructor that schedules a function to be called after a timeout.

Parameters
funcThe function to execute. It will be moved into the Timeout object.
timeoutTimeout 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.

Member Function Documentation

◆ on()

template<typename _Func>
void qb::io::async::Timeout< _Func >::on ( event::timer const & ) const
inline

Timer event handler called when the timeout expires.

Parameters
eventThe 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.