Core mechanisms for event-driven asynchronous programming.
More...
|
file | io_handler.h |
| Session management for the asynchronous IO framework.
|
file | listener.h |
| Core event loop manager for the asynchronous IO framework.
|
|
template<typename _Func> |
void | qb::io::async::callback (_Func &&func, double timeout=0.) |
| Utility function to schedule a callable for execution after a timeout.
|
void | qb::io::async::init () |
| Initialize the asynchronous event system for the current thread.
|
std::size_t | qb::io::async::run (int flag=0) |
| Run the event loop for the current thread.
|
std::size_t | qb::io::async::run_once () |
| Run the event loop once for the current thread, waiting for at least one event.
|
std::size_t | qb::io::async::run_until (bool const &status) |
| Run the event loop for the current thread until a condition is met.
|
void | qb::io::async::break_parent () |
| Request the parent (current thread's) event loop to break.
|
Core mechanisms for event-driven asynchronous programming.
Includes the event listener (`qb::io::async::listener`), base async I/O classes (`qb::io::async::io`), and timed callbacks (`qb::io::async::callback`).
◆ callback()
template<typename _Func>
void qb::io::async::callback |
( |
_Func && | func, |
|
|
double | timeout = 0. ) |
Utility function to schedule a callable for execution after a timeout.
- Template Parameters
-
_Func | The type of the callable (function, lambda, functor). |
- Parameters
-
func | The callable to execute. It is moved into the internal Timeout object. |
timeout | Timeout duration in seconds before execution. A timeout of 0.0 (or less) typically means the callback will be scheduled for the next iteration of the event loop, or executed immediately if the Timeout class logic handles it that way. |
This function creates a Timeout<_Func> object on the heap (new Timeout), which then manages its own lifetime, deleting itself after func is called. It provides a convenient way to achieve delayed execution without manual timer management.
◆ init()
void qb::io::async::init |
( |
| ) |
|
|
inline |
Initialize the asynchronous event system for the current thread.
Ensures that listener::current is available and ready for use. Typically called once per thread that will use qb-io asynchronous features standalone. Not usually needed when using qb-core as qb::Main handles this for its VirtualCore threads.
◆ run()
std::size_t qb::io::async::run |
( |
int | flag = 0 | ) |
|
|
inline |
Run the event loop for the current thread.
Executes the current thread's listener::current.run(flag). This is the primary way to process asynchronous events in a standalone qb-io application.
- Parameters
-
flag | The libev run flag (e.g., EVRUN_NOWAIT, EVRUN_ONCE). See listener::run(). |
- Returns
- The number of events that were invoked during this run.
◆ run_once()
std::size_t qb::io::async::run_once |
( |
| ) |
|
|
inline |
Run the event loop once for the current thread, waiting for at least one event.
Equivalent to listener::current.run(EVRUN_ONCE).
- Returns
- The number of events invoked.
◆ run_until()
std::size_t qb::io::async::run_until |
( |
bool const & | status | ) |
|
|
inline |
Run the event loop for the current thread until a condition is met.
Repeatedly calls listener::current.run(EVRUN_NOWAIT) as long as the status is true.
- Parameters
-
status | Reference to a boolean condition. The loop continues as long as status is true. |
- Returns
- The total number of events invoked across all run(EVRUN_NOWAIT) calls.
◆ break_parent()
void qb::io::async::break_parent |
( |
| ) |
|
|
inline |
Request the parent (current thread's) event loop to break.
Calls listener::current.break_one().