drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon::Topic< MessageType > Class Template Reference

This class template presents an unnamed topic. More...

#include <drogon/PubSubService.h>

Inheritance diagram for drogon::Topic< MessageType >:
Collaboration diagram for drogon::Topic< MessageType >:

Public Types

using MessageHandler = std::function<void(const MessageType &)>
using SharedMutex = std::shared_timed_mutex

Public Member Functions

void publish (const MessageType &message) const
 Publish a message, every subscriber in the topic will receive the message.
SubscriberID subscribe (const MessageHandler &handler)
 Subscribe to the topic.
SubscriberID subscribe (MessageHandler &&handler)
 Subscribe to the topic.
void unsubscribe (SubscriberID id)
 Unsubscribe from the topic.
bool empty () const
 Check if the topic is empty.
void clear ()
 Remove all subscribers from the topic.

Detailed Description

template<typename MessageType>
class drogon::Topic< MessageType >

This class template presents an unnamed topic.

Template Parameters
MessageType

Member Function Documentation

◆ empty()

template<typename MessageType>
bool drogon::Topic< MessageType >::empty ( ) const
inline

Check if the topic is empty.

Returns
true means there are no subscribers.
false means there are subscribers in the topic.

◆ publish()

template<typename MessageType>
void drogon::Topic< MessageType >::publish ( const MessageType & message) const
inline

Publish a message, every subscriber in the topic will receive the message.

Parameters
message

◆ subscribe() [1/2]

template<typename MessageType>
SubscriberID drogon::Topic< MessageType >::subscribe ( const MessageHandler & handler)
inline

Subscribe to the topic.

Parameters
handleris invoked when a message arrives.
Returns
SubscriberID

◆ subscribe() [2/2]

template<typename MessageType>
SubscriberID drogon::Topic< MessageType >::subscribe ( MessageHandler && handler)
inline

Subscribe to the topic.

Parameters
handleris invoked when a message arrives.
Returns
SubscriberID

The documentation for this class was generated from the following file: