Monitors Async I/O events from a background thread using a blocking kernel function (no CPU usage on idle). More...
#include <Async.h>
Public Member Functions | |
Result | create (AsyncEventLoop &loop) |
Create the monitoring thread for an AsyncEventLoop. More... | |
Result | close () |
Stop monitoring the AsyncEventLoop, disposing all resources. More... | |
Result | startMonitoring () |
Queue all async requests submissions and start monitoring loop events on a background thread. More... | |
Result | stopMonitoringAndDispatchCompletions () |
Stops monitoring events on the background thread and dispatches callbacks for completed requests. More... | |
Public Attributes | |
Function< void(void)> | onNewEventsAvailable |
Informs to call dispatchCompletions on GUI Event Loop. More... | |
Monitors Async I/O events from a background thread using a blocking kernel function (no CPU usage on idle).
AsyncEventLoopMonitor makes it easy to integrate AsyncEventLoop within a GUI event loop or another I/O event loop. This pattern avoids constantly polling the kernel, using virtually 0% of CPU time when waiting for events.
Result SC::AsyncEventLoopMonitor::close | ( | ) |
Stop monitoring the AsyncEventLoop, disposing all resources.
Result SC::AsyncEventLoopMonitor::create | ( | AsyncEventLoop & | loop | ) |
Create the monitoring thread for an AsyncEventLoop.
To start monitoring events call AsyncEventLoopMonitor::startMonitoring.
Result SC::AsyncEventLoopMonitor::startMonitoring | ( | ) |
Queue all async requests submissions and start monitoring loop events on a background thread.
On the background thread AsyncEventLoop::blockingPoll will block (with 0% CPU usage) and return only when it will be informed by the kernel of some new events. Immediately after AsyncEventLoopMonitor::onNewEventsAvailable will be called (on the background thread). In the code handler associated with this event, the user/caller should inform its main thread to call AsyncEventLoopMonitor::stopMonitoringAndDispatchCompletions.
Result SC::AsyncEventLoopMonitor::stopMonitoringAndDispatchCompletions | ( | ) |
Stops monitoring events on the background thread and dispatches callbacks for completed requests.
This is typically called by the user of this class on the main thread or in general on the thread where the event loop that coordinates the application lives (GUI thread typically or another I/O Event Loop thread).
Function<void(void)> SC::AsyncEventLoopMonitor::onNewEventsAvailable |
Informs to call dispatchCompletions on GUI Event Loop.