#include <icy/runner.h>Subclassed by:
Idler,Synchronizer,Thread,Timer
Runner is a virtual interface for implementing asynchronous objects such as threads and futures.
| Return | Name | Description |
|---|---|---|
Runner | ||
void | start | Starts the asynchronous context with the given callback. The callback must remain valid for the lifetime of the [Runner](#runner). |
bool | running const | Returns true if the async context is currently running. |
void | cancel | Signals the async context to stop at the earliest opportunity. |
bool | cancelled const | Returns true if the context has been cancelled. The implementation is responsible for exiting as soon as possible after cancellation. |
bool | repeating const | Returns true if the runner is in repeating mode. |
void | setRepeating | Enables or disables repeating mode. When repeating, the target function is invoked repeatedly until [cancel()](#cancel-2) is called. This normalizes behaviour across thread-based and event-loop-based [Runner](#runner) implementations. Must be called before [start()](#start-3). |
bool | async const | Returns true if the implementation is thread-based. |
std::thread::id | tid const | Returns the native thread ID of the thread running the async context. |
bool | waitForExit | Blocks until the async context exits or the timeout elapses. The context should be cancelled before calling this method. Must be called from outside the runner's own thread to avoid deadlock. |
Runner()void start(std::function< void()> target)Starts the asynchronous context with the given callback. The callback must remain valid for the lifetime of the [Runner](#runner).
target Callable to invoke when the context runs.const
bool running() constReturns true if the async context is currently running.
True if the runner's context has been started and has not yet stopped.
void cancel()Signals the async context to stop at the earliest opportunity.
const
bool cancelled() constReturns true if the context has been cancelled. The implementation is responsible for exiting as soon as possible after cancellation.
True if [cancel()](#cancel-2) has been called.
const
bool repeating() constReturns true if the runner is in repeating mode.
True if the target function is invoked in a loop until cancelled.
void setRepeating(bool flag)Enables or disables repeating mode. When repeating, the target function is invoked repeatedly until [cancel()](#cancel-2) is called. This normalizes behaviour across thread-based and event-loop-based [Runner](#runner) implementations. Must be called before [start()](#start-3).
flag True to enable repeating mode, false to run the target once.const
bool async() constReturns true if the implementation is thread-based.
True for thread-backed runners, false for event-loop-driven runners.
const
std::thread::id tid() constReturns the native thread ID of the thread running the async context.
std::thread::id of the runner thread, or a default-constructed ID if not started.
bool waitForExit(int timeout)Blocks until the async context exits or the timeout elapses. The context should be cancelled before calling this method. Must be called from outside the runner's own thread to avoid deadlock.
timeout Maximum number of milliseconds to wait. Pass 0 to wait indefinitely.True if the context exited cleanly, false if the timeout was reached (throws instead).
std::shared_ptr< Context > _contextShared pointer to the internal Context.
Runner(const Runner &) = deleteNonCopyable and NonMovable.
Runner(Runner &&) = deleteDeleted constructor.