mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Stop the 7tv heartbeat timer on shutdown request
This commit is contained in:
parent
ca97fa4d76
commit
934e518e18
3 changed files with 27 additions and 8 deletions
|
@ -150,6 +150,15 @@ protected:
|
|||
return this->started_.load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Will be called when the clients has been requested to stop
|
||||
*
|
||||
* Derived classes can override this to do their own shutdown behaviour
|
||||
*/
|
||||
virtual void stopImpl()
|
||||
{
|
||||
}
|
||||
|
||||
liveupdates::WebsocketClient &websocketClient_;
|
||||
|
||||
private:
|
||||
|
@ -164,6 +173,8 @@ private:
|
|||
{
|
||||
assert(this->isStarted());
|
||||
this->started_.store(false, std::memory_order_release);
|
||||
|
||||
this->stopImpl();
|
||||
}
|
||||
|
||||
liveupdates::WebsocketHandle handle_;
|
||||
|
|
|
@ -13,6 +13,8 @@ Client::Client(liveupdates::WebsocketClient &websocketClient,
|
|||
: BasicPubSubClient<Subscription>(websocketClient, std::move(handle))
|
||||
, lastHeartbeat_(std::chrono::steady_clock::now())
|
||||
, heartbeatInterval_(heartbeatInterval)
|
||||
, heartbeatTimer_(std::make_shared<boost::asio::steady_timer>(
|
||||
this->websocketClient_.get_io_service()))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -23,6 +25,11 @@ void Client::onConnectionEstablished()
|
|||
this->checkHeartbeat();
|
||||
}
|
||||
|
||||
void Client::stopImpl()
|
||||
{
|
||||
this->heartbeatTimer_->cancel();
|
||||
}
|
||||
|
||||
void Client::setHeartbeatInterval(int intervalMs)
|
||||
{
|
||||
qCDebug(chatterinoSeventvEventAPI)
|
||||
|
@ -54,14 +61,13 @@ void Client::checkHeartbeat()
|
|||
|
||||
auto self = std::dynamic_pointer_cast<Client>(this->shared_from_this());
|
||||
|
||||
runAfter(this->websocketClient_.get_io_service(), this->heartbeatInterval_,
|
||||
[self](auto) {
|
||||
if (!self->isStarted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
self->checkHeartbeat();
|
||||
});
|
||||
runAfter(this->heartbeatTimer_, this->heartbeatInterval_, [self](auto) {
|
||||
if (!self->isStarted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
self->checkHeartbeat();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace chatterino::seventv::eventapi
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
|
||||
protected:
|
||||
void onConnectionEstablished() override;
|
||||
void stopImpl() override;
|
||||
|
||||
private:
|
||||
void checkHeartbeat();
|
||||
|
@ -32,6 +33,7 @@ private:
|
|||
lastHeartbeat_;
|
||||
// This will be set once on the welcome message.
|
||||
std::chrono::milliseconds heartbeatInterval_;
|
||||
std::shared_ptr<boost::asio::steady_timer> heartbeatTimer_;
|
||||
|
||||
friend SeventvEventAPI;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue