Function unsubscribe

Synopsis

#include <lib/inc/drogon/PubSubService.h>

void unsubscribe(const std::string &topicName, SubscriberID id)

Description

Unsubscribe from a topic.

Parameters:

topic -

id - The subscriber ID returned from the subscribe method.

Source

Lines 192-213 in lib/inc/drogon/PubSubService.h.

void unsubscribe(const std::string &topicName, SubscriberID id)
{
    {
        std::shared_lock<SharedMutex> lock(mutex_);
        auto iter = topicMap_.find(topicName);
        if (iter == topicMap_.end())
        {
            return;
        }
        iter->second->unsubscribe(id);
        if (!iter->second->empty())
            return;
    }
    std::unique_lock<SharedMutex> lock(mutex_);
    auto iter = topicMap_.find(topicName);
    if (iter == topicMap_.end())
    {
        return;
    }
    if (iter->second->empty())
        topicMap_.erase(iter);
}





Add Discussion as Guest

Log in to DocsForge