Fix timer stuff (#580)

* Add and sort Network files to chatterino project file
This commit is contained in:
pajlada
2018-07-07 15:50:05 +02:00
committed by GitHub
parent 55269587f5
commit 2ea3643100
5 changed files with 62 additions and 45 deletions
+39
View File
@@ -0,0 +1,39 @@
#include "common/NetworkTimer.hpp"
#include "common/NetworkWorker.hpp"
#include <QTimer>
#include <cassert>
namespace chatterino {
void NetworkTimer::start()
{
if (this->timeoutMS_ <= 0) {
return;
}
this->timer_ = new QTimer;
this->timer_->start(this->timeoutMS_);
QObject::connect(this->timer_, &QTimer::timeout, [timer = this->timer_] {
timer->deleteLater(); //
});
this->started_ = true;
}
bool NetworkTimer::isStarted() const
{
return this->started_;
}
void NetworkTimer::onTimeout(NetworkWorker *worker, std::function<void()> cb) const
{
assert(this->timer_ != nullptr);
assert(worker != nullptr);
QObject::connect(this->timer_, &QTimer::timeout, worker, cb);
}
} // namespace chatterino