Thread-affine callback registry with mutation-safe dispatch. 更多...
#include <Subscription.h>
Public 类型 | |
| using | Callback = std::function< void(const Args &...)> |
Public 成员函数 | |
| Observer () | |
| Constructs a Observer. | |
| Observer (const Observer &)=delete | |
| Observer & | operator= (const Observer &)=delete |
| Observer (Observer &&)=delete | |
| Observer & | operator= (Observer &&)=delete |
| ~Observer ()=default | |
| Releases Observer resources. | |
| Subscription | subscribe (Callback callback) |
| Registers a callback owned by the returned Subscription. | |
| void | notify (const Args &...args) |
| Synchronously notifies a snapshot of current registrations. | |
| template<typename FailureHandler > | |
| std::size_t | notifyChecked (FailureHandler &&onFailure, const Args &...args) |
| Notifies all snapshotted callbacks and contains unknown exceptions. | |
| std::size_t | size () const noexcept |
| Returns the number of currently active registrations. | |
| void | compactInactive () |
| Removes inactive entries without invoking user callbacks. | |
详细描述
class eve::Observer< Args >
Thread-affine callback registry with mutation-safe dispatch.
Observer is intentionally a small lifecycle primitive, not an event bus or a synchronization primitive. All methods, including destruction of the returned Subscription, must be called from the owner thread. notify() invokes callbacks synchronously on its caller and holds no lock while an unknown callback runs.
Dispatch is reentrant. A callback may subscribe or dispose any token, including its own. Registrations added during a dispatch are considered on the next dispatch; registrations disposed before their turn are skipped. The callback currently running is allowed to finish. Recursive notify calls are supported, but callers must bound recursion themselves.
- 模板参数
-
Args Callback argument types, passed as const references.
Observer public API.
在文件 Subscription.h 第 82 行定义.
成员类型定义说明
◆ Callback
| using eve::Observer< Args >::Callback = std::function<void(const Args &...)> |
在文件 Subscription.h 第 84 行定义.
构造及析构函数说明
◆ Observer() [1/3]
|
inline |
Constructs a Observer.
在文件 Subscription.h 第 87 行定义.
◆ Observer() [2/3]
|
delete |
◆ Observer() [3/3]
|
delete |
◆ ~Observer()
|
default |
Releases Observer resources.
成员函数说明
◆ compactInactive()
|
inline |
Removes inactive entries without invoking user callbacks.
Erases if.
在文件 Subscription.h 第 177 行定义.
被这些函数引用 eve::Observer< Args >::subscribe().
◆ notify()
|
inline |
Synchronously notifies a snapshot of current registrations.
- 参数
-
args Values passed to each active callback as borrowed references.
- 警告
- The arguments must remain valid for the duration of this call.
在文件 Subscription.h 第 127 行定义.
引用了 callback.
◆ notifyChecked()
|
inline |
Notifies all snapshotted callbacks and contains unknown exceptions.
- 参数
-
onFailure Non-throwing handler called once per callback exception. args Values passed to each active callback as borrowed references.
- 返回
- Number of callbacks that threw; committed caller state is not rolled back or reported as an operation failure.
- 备注
- Registrations added or disposed during dispatch follow the same next-dispatch rules as notify().
Notify checked.
Callback.
在文件 Subscription.h 第 150 行定义.
引用了 callback.
◆ operator=() [1/2]
|
delete |
◆ operator=() [2/2]
|
delete |
◆ size()
|
inlinenoexcept |
◆ subscribe()
|
inline |
Registers a callback owned by the returned Subscription.
- 参数
-
callback Callback invoked by notify; an empty callback is ignored.
- 返回
- Move-only token that cancels this registration when disposed.
- 警告
- Call this method and dispose the returned token on the owner thread.
Erases if.
在文件 Subscription.h 第 101 行定义.
引用了 callback, eve::Observer< Args >::compactInactive() , 以及 state.
该类的文档由以下文件生成:
- src/engine/common/Subscription.h