JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
jh::async::event_signal< T > Class Template Referencefinal

Lightweight push-only event emitter. More...

#include <jh/asynchronous/slot.h>

Public Member Functions

void connect (listener< T > *l) noexcept
 Connect this signal to a listener.
template<typename... Args>
bool emit (Args &&... args)
 Emit a value to the connected listener.

Detailed Description

template<typename T>
class jh::async::event_signal< T >

Lightweight push-only event emitter.

Positioning

An event_signal provides a user-facing injection mechanism. It does not store or buffer events. It only forwards emit() into its connected listener.

event_signal can have a shorter lifespan than the connected listener, but it cannot have a longer lifespan (dangling). In particular, after a slot coroutine switches the listening object between different states, the event_signal can be recycled by running out of scope.

Semantics

  • connect(listener*) must be called before the first emit().
  • emit() must be called after the slot has been spawned.
  • emit(...) delegates synchronously to listener.invoke().
  • If the hub's mutex cannot be acquired in time, the event is rejected.
Template Parameters
TPayload type.
Note
An event_signal never performs fan-out nor routing. All routing, filtering, switching and fan-out are handled inside the slot coroutine.
Warning
Must not outlive the listener it is connected to.

Member Function Documentation

◆ connect()

template<typename T>
void jh::async::event_signal< T >::connect ( listener< T > * l)
inlinenoexcept

Connect this signal to a listener.

The signal will deliver emitted events to this listener.

Parameters
lPointer to the listener.

◆ emit()

template<typename T>
template<typename... Args>
bool jh::async::event_signal< T >::emit ( Args &&... args)
inline

Emit a value to the connected listener.

Invokes listener's inbox delivery logic with constructed value.

Template Parameters
ArgsConstructor arguments for T.
Parameters
argsArguments to construct the value.
Returns
true if delivery succeeded, false otherwise.

The documentation for this class was generated from the following file:
  • include/jh/asynchronous/slot.h