Base module

Idler

Asynchronous type that triggers callbacks when the event loop is idle.

#include <icy/idler.h>

class Idler

Defined in src/base/include/icy/idler.h:31

Inherits
Runner

This class inherits the Runner interface and may be used with any implementation that's powered by an asynchronous Runner.

List of all members

NameKindOwner
IdlerfunctionDeclared here
IdlerfunctionDeclared here
IdlerfunctionDeclared here
startfunctionDeclared here
startfunctionDeclared here
~IdlerfunctionDeclared here
handlefunctionDeclared here
_handlevariableDeclared here
initfunctionDeclared here
asyncfunctionDeclared here
RunnerfunctionInherited from Runner
~RunnerfunctionInherited from Runner
startfunctionInherited from Runner
runningfunctionInherited from Runner
cancelfunctionInherited from Runner
cancelledfunctionInherited from Runner
repeatingfunctionInherited from Runner
setRepeatingfunctionInherited from Runner
asyncfunctionInherited from Runner
tidfunctionInherited from Runner
waitForExitfunctionInherited from Runner
_contextvariableInherited from Runner
RunnerfunctionInherited from Runner
operator=functionInherited from Runner
RunnerfunctionInherited from Runner
operator=functionInherited from Runner

Inherited from Runner

KindNameDescription
functionRunner
function~Runner virtual
functionstart virtualStarts the asynchronous context with the given callback. The callback must remain valid for the lifetime of the Runner.
functionrunning constReturns true if the async context is currently running.
functioncancelSignals the async context to stop at the earliest opportunity.
functioncancelled constReturns true if the context has been cancelled. The implementation is responsible for exiting as soon as possible after cancellation.
functionrepeating constReturns true if the runner is in repeating mode.
functionsetRepeatingEnables 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().
functionasync virtual constReturns true if the implementation is thread-based.
functiontid constReturns the native thread ID of the thread running the async context.
functionwaitForExitBlocks 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.
variable_contextShared pointer to the internal Context.
functionRunnerNonCopyable and NonMovable.
functionoperator=Deleted assignment operator.
functionRunnerDeleted constructor.
functionoperator=Deleted assignment operator.

Public Methods

ReturnNameDescription
IdlerCreate the idler bound to loop without starting it.
Idler inline explicitCreate and immediately start the idler on the default loop.
Idler inline explicitCreate and immediately start the idler on the given loop.
voidstart inlineStart the idler, invoking func (with args) on every idle iteration.
voidstart virtual overrideStart the idler with a type-erased callback (implements Runner::start).
~Idler virtualDefaulted destructor.
uv::Handle< uv_idle_t > &handle

Idler

Idler(uv::Loop * loop = uv::defaultLoop())

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

Create the idler bound to loop without starting it.

Parameters

ParameterTypeDescription
loopuv::Loop *Event loop to associate with. Defaults to the process-wide default loop.

Idler

inline explicit

template<typename Function, typename... Args> inline explicit Idler(Function && func, Args &&... args)

Defined in src/base/include/icy/idler.h:44

Create and immediately start the idler on the default loop.

Parameters

ParameterTypeDescription
funcFunction &&Callable invoked on every idle iteration.
argsArgs &&...Arguments forwarded to func.

Idler

inline explicit

template<typename Function, typename... Args> inline explicit Idler(uv::Loop * loop, Function && func, Args &&... args)

Defined in src/base/include/icy/idler.h:57

Create and immediately start the idler on the given loop.

Parameters

ParameterTypeDescription
loopuv::Loop *Event loop to associate with.
funcFunction &&Callable invoked on every idle iteration.
argsArgs &&...Arguments forwarded to func.

start

inline

template<typename Function, typename... Args> inline void start(Function && func, Args &&... args)

Defined in src/base/include/icy/idler.h:73

Start the idler, invoking func (with args) on every idle iteration.

The idler always runs in repeating mode; cancel via Runner::cancel(). Throws std::logic_error if the handle is already active or the runner context reports it is still running.

Parameters

ParameterTypeDescription
funcFunction &&Callable invoked each time the event loop is idle.
argsArgs &&...Arguments forwarded to func on each invocation.

start

virtual override

virtual void start(std::function< void()> func) override

Defined in src/base/include/icy/idler.h:118

Start the idler with a type-erased callback (implements Runner::start).

Reimplements

Parameters

ParameterTypeDescription
funcstd::function< void()>Callback invoked on every idle iteration.

~Idler

virtual

virtual ~Idler() = default

Defined in src/base/include/icy/idler.h:120

Defaulted destructor.


handle

uv::Handle< uv_idle_t > & handle()

Defined in src/base/include/icy/idler.h:123

Returns

Reference to the underlying uv_idle_t handle wrapper.

Protected Attributes

ReturnNameDescription
uv::Handle< uv_idle_t >_handle

_handle

uv::Handle< uv_idle_t > _handle

Type: uv::Handle< uv_idle_t >

Defined in src/base/include/icy/idler.h:132

Protected Methods

ReturnNameDescription
voidinit virtualInitialize the underlying uv_idle_t handle and unref it from the loop.
boolasync virtual const override

init

virtual

virtual void init()

Defined in src/base/include/icy/idler.h:127

Initialize the underlying uv_idle_t handle and unref it from the loop.


async

virtual const override

virtual bool async() const override

Defined in src/base/include/icy/idler.h:130

Returns

false; the idler is event-loop-driven, not thread-based.

Reimplements