载入中...
搜索中...
未找到
eve::Observer< Args > 模板类 参考

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.
 

详细描述

template<typename... Args>
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.

模板参数
ArgsCallback argument types, passed as const references.

Observer public API.

在文件 Subscription.h 第 82 行定义.

成员类型定义说明

◆ Callback

template<typename... Args>
using eve::Observer< Args >::Callback = std::function<void(const Args &...)>

在文件 Subscription.h 第 84 行定义.

构造及析构函数说明

◆ Observer() [1/3]

template<typename... Args>
eve::Observer< Args >::Observer ( )
inline

Constructs a Observer.

在文件 Subscription.h 第 87 行定义.

◆ Observer() [2/3]

template<typename... Args>
eve::Observer< Args >::Observer ( const Observer< Args > &  )
delete

◆ Observer() [3/3]

template<typename... Args>
eve::Observer< Args >::Observer ( Observer< Args > &&  )
delete

◆ ~Observer()

template<typename... Args>
eve::Observer< Args >::~Observer ( )
default

Releases Observer resources.

成员函数说明

◆ compactInactive()

template<typename... Args>
void eve::Observer< Args >::compactInactive ( )
inline

Removes inactive entries without invoking user callbacks.

Erases if.

在文件 Subscription.h 第 177 行定义.

被这些函数引用 eve::Observer< Args >::subscribe().

◆ notify()

template<typename... Args>
void eve::Observer< Args >::notify ( const Args &...  args)
inline

Synchronously notifies a snapshot of current registrations.

参数
argsValues passed to each active callback as borrowed references.
警告
The arguments must remain valid for the duration of this call.

在文件 Subscription.h 第 127 行定义.

引用了 callback.

◆ notifyChecked()

template<typename... Args>
template<typename FailureHandler >
std::size_t eve::Observer< Args >::notifyChecked ( FailureHandler &&  onFailure,
const Args &...  args 
)
inline

Notifies all snapshotted callbacks and contains unknown exceptions.

参数
onFailureNon-throwing handler called once per callback exception.
argsValues 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]

template<typename... Args>
Observer & eve::Observer< Args >::operator= ( const Observer< Args > &  )
delete

◆ operator=() [2/2]

template<typename... Args>
Observer & eve::Observer< Args >::operator= ( Observer< Args > &&  )
delete

◆ size()

template<typename... Args>
std::size_t eve::Observer< Args >::size ( ) const
inlinenoexcept

Returns the number of currently active registrations.

在文件 Subscription.h 第 169 行定义.

引用了 count.

◆ subscribe()

template<typename... Args>
Subscription eve::Observer< Args >::subscribe ( Callback  callback)
inline

Registers a callback owned by the returned Subscription.

参数
callbackCallback 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.

Subscription.

Erases if.

在文件 Subscription.h 第 101 行定义.

引用了 callback, eve::Observer< Args >::compactInactive() , 以及 state.


该类的文档由以下文件生成: