Possibly fixed PubSub over 50 listens

Keep an eye out on #1189
This commit is contained in:
Rasmus Karlsson 2019-09-21 12:46:10 +02:00
parent 137d7910c0
commit 5871414e6b

View file

@ -729,7 +729,7 @@ PubSub::PubSub()
// Add an initial client
this->addClient();
} // namespace chatterino
}
void PubSub::addClient()
{
@ -818,6 +818,8 @@ void PubSub::listen(rapidjson::Document &&msg)
return;
}
this->addClient();
log("Added to the back of the queue");
this->requests.emplace_back(
std::make_unique<rapidjson::Document>(std::move(msg)));
@ -936,6 +938,19 @@ void PubSub::onConnectionOpen(WebsocketHandle hdl)
this->clients.emplace(hdl, client);
this->connected.invoke();
for (auto it = this->requests.begin(); it != this->requests.end();)
{
const auto &request = *it;
if (client->listen(*request))
{
it = this->requests.erase(it);
}
else
{
++it;
}
}
}
void PubSub::onConnectionClose(WebsocketHandle hdl)