Base module

Runner

Runner is a virtual interface for implementing asynchronous objects such as threads and f

#include <icy/runner.h>

class Runner

Defined in src/base/include/icy/runner.h:34

Subclassed by
Idler, Synchronizer, Thread, Timer

Runner is a virtual interface for implementing asynchronous objects such as threads and futures.

Public Methods

ReturnNameDescription
Runner
~Runner virtual
voidstart virtualStarts the asynchronous context with the given callback. The callback must remain valid for the lifetime of the Runner.
boolrunning constReturns true if the async context is currently running.
voidcancelSignals the async context to stop at the earliest opportunity.
boolcancelled constReturns true if the context has been cancelled. The implementation is responsible for exiting as soon as possible after cancellation.
boolrepeating constReturns true if the runner is in repeating mode.
voidsetRepeatingEnables or disables repeating mode. When repeating, the target function is invoked repeatedly until cancel() is called. This normalizes behaviour across thread-based and event-loop-based Runner implementations. Must be called before start().
boolasync virtual constReturns true if the implementation is thread-based.
std::thread::idtid constReturns the native thread ID of the thread running the async context.
boolwaitForExitBlocks 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

Runner()

Defined in src/base/include/icy/runner.h:37


~Runner

virtual

virtual ~Runner()

Defined in src/base/include/icy/runner.h:38


start

virtual

virtual void start(std::function< void()> target)

Defined in src/base/include/icy/runner.h:43

Starts the asynchronous context with the given callback. The callback must remain valid for the lifetime of the Runner.

Reimplemented by

Parameters

ParameterTypeDescription
targetstd::function< void()>Callable to invoke when the context runs.

running

const

bool running() const

Defined in src/base/include/icy/runner.h:47

Returns true if the async context is currently running.

Returns

True if the runner's context has been started and has not yet stopped.


cancel

void cancel()

Defined in src/base/include/icy/runner.h:50

Signals the async context to stop at the earliest opportunity.


cancelled

const

bool cancelled() const

Defined in src/base/include/icy/runner.h:55

Returns true if the context has been cancelled. The implementation is responsible for exiting as soon as possible after cancellation.

Returns

True if cancel() has been called.


repeating

const

bool repeating() const

Defined in src/base/include/icy/runner.h:59

Returns true if the runner is in repeating mode.

Returns

True if the target function is invoked in a loop until cancelled.


setRepeating

void setRepeating(bool flag)

Defined in src/base/include/icy/runner.h:66

Enables or disables repeating mode. When repeating, the target function is invoked repeatedly until cancel() is called. This normalizes behaviour across thread-based and event-loop-based Runner implementations. Must be called before start().

Parameters

ParameterTypeDescription
flagboolTrue to enable repeating mode, false to run the target once.

async

virtual const

virtual bool async() const

Defined in src/base/include/icy/runner.h:70

Returns true if the implementation is thread-based.

Returns

True for thread-backed runners, false for event-loop-driven runners.

Reimplemented by


tid

const

std::thread::id tid() const

Defined in src/base/include/icy/runner.h:74

Returns the native thread ID of the thread running the async context.

Returns

std::thread::id of the runner thread, or a default-constructed ID if not started.


waitForExit

bool waitForExit(int timeout = 5000)

Defined in src/base/include/icy/runner.h:81

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.

Returns

True if the context exited cleanly, false if the timeout was reached (throws instead).

Parameters

ParameterTypeDescription
timeoutintMaximum number of milliseconds to wait. Pass 0 to wait indefinitely.

Protected Attributes

ReturnNameDescription
std::shared_ptr< Context >_contextShared pointer to the internal Context.

_context

std::shared_ptr< Context > _context

Type: std::shared_ptr< Context >

Defined in src/base/include/icy/runner.h:117

Shared pointer to the internal Context.

Protected Methods

ReturnNameDescription
RunnerNonCopyable and NonMovable.
Runner &operator=Deleted assignment operator.
RunnerDeleted constructor.
Runner &operator=Deleted assignment operator.

Runner

Runner(const Runner &) = delete

Defined in src/base/include/icy/runner.h:111

NonCopyable and NonMovable.


operator=

Runner & operator=(const Runner &) = delete

Defined in src/base/include/icy/runner.h:112

Deleted assignment operator.


Runner

Runner(Runner &&) = delete

Defined in src/base/include/icy/runner.h:113

Deleted constructor.


operator=

Runner & operator=(Runner &&) = delete

Defined in src/base/include/icy/runner.h:114

Deleted assignment operator.