mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
1043f9f803
* refactor: remove unnecessary includes in headers * fix: formatting * chore: changelog * fix: scrollbar * fix: suggestions and old appbase remains * fix: suggestion * fix: missing Qt forward declarations * fix: another qt include * fix: includes for precompiled-headers=off * Add missing `<memory>` includes * Add missing `#pragma once` * Fix tests Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "common/QLogging.hpp"
|
|
|
|
#include <boost/asio.hpp>
|
|
#include <boost/asio/steady_timer.hpp>
|
|
|
|
#include <memory>
|
|
|
|
namespace chatterino {
|
|
|
|
class TwitchAccount;
|
|
struct ActionUser;
|
|
|
|
// Create timer using given ioService
|
|
template <typename Duration, typename Callback>
|
|
void runAfter(boost::asio::io_service &ioService, Duration duration,
|
|
Callback cb)
|
|
{
|
|
auto timer = std::make_shared<boost::asio::steady_timer>(ioService);
|
|
timer->expires_from_now(duration);
|
|
|
|
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
|
|
if (ec)
|
|
{
|
|
qCDebug(chatterinoPubSub)
|
|
<< "Error in runAfter:" << ec.message().c_str();
|
|
return;
|
|
}
|
|
|
|
cb(timer);
|
|
});
|
|
}
|
|
|
|
// Use provided timer
|
|
template <typename Duration, typename Callback>
|
|
void runAfter(std::shared_ptr<boost::asio::steady_timer> timer,
|
|
Duration duration, Callback cb)
|
|
{
|
|
timer->expires_from_now(duration);
|
|
|
|
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
|
|
if (ec)
|
|
{
|
|
qCDebug(chatterinoPubSub)
|
|
<< "Error in runAfter:" << ec.message().c_str();
|
|
return;
|
|
}
|
|
|
|
cb(timer);
|
|
});
|
|
}
|
|
|
|
} // namespace chatterino
|