|
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.
|
A one-shot inbox that serves as the fan-in aggregation point. More...
#include <jh/asynchronous/slot.h>
Public Types | |
| using | value_type = T |
| The type of value delivered to this listener. | |
Public Member Functions | |
| bool | await_ready () const noexcept |
| Check if the coroutine should resume immediately. | |
| void | await_suspend (std::coroutine_handle<> h) noexcept |
| Register coroutine handle for resumption. | |
| T | await_resume () |
| Resume coroutine and consume the value. | |
| template<typename... Args> | |
| bool | invoke (Args &&... args) |
| Deliver a new value to this listener. | |
Friends | |
| class | slot_hub |
| Enables slot_hub to create listeners. | |
A one-shot inbox that serves as the fan-in aggregation point.
A listener cannot be created directly.
It must always be constructed through slot_hub::make_listener<T>().
This restriction is intentional: a listener without an associated slot_hub is semantically meaningless. A listener's fundamental responsibilities—synchronous delivery, timed-mutex protection, and slot resumption—require a slot_hub context. Thus, its constructor is private and slot_hub acts as the factory and parent domain.
A listener represents a single suspension point for the slot. It aggregates events coming from one or more event_signal objects and delivers them synchronously to the slot.
A listener supports:
event_signal<T> → listener<T> event_signal<T> → same listener<T> (sources are indistinguishable) await_resume(). slot_hub mutex. | T | Payload type delivered to the slot. |
slot must only await one listener at a time. Parallel awaits violate the asynchronous semantics and are strongly discouraged.slot_hub and slot.
|
inlinenodiscardnoexcept |
Check if the coroutine should resume immediately.
Always returns false to suspend the coroutine.
|
inline |
Resume coroutine and consume the value.
Extracts the stored value from the inbox and clears it.
|
inlinenoexcept |
Register coroutine handle for resumption.
Stores the coroutine handle to resume later when value is delivered.
| h | Coroutine handle. |
|
inline |
Deliver a new value to this listener.
Attempts to acquire the mutex, store the value, and resume the attached slot.
| Args | Constructor arguments for T. |
| args | Arguments to construct the value. |