mirror-chatterino2/src/asyncexec.hpp

28 lines
436 B
C++
Raw Normal View History

#pragma once
2017-01-04 15:12:31 +01:00
#include <QCoreApplication>
2017-01-04 15:12:31 +01:00
2017-01-18 04:52:47 +01:00
#include <QRunnable>
#include <QThreadPool>
2017-01-18 21:30:23 +01:00
#include <functional>
2017-01-18 04:52:47 +01:00
2017-04-12 17:46:44 +02:00
#define async_exec(a) QThreadPool::globalInstance()->start(new LambdaRunnable(a));
2017-01-18 21:30:23 +01:00
class LambdaRunnable : public QRunnable
{
2017-01-18 21:30:23 +01:00
public:
LambdaRunnable(std::function<void()> action)
{
this->action = action;
}
2017-04-12 17:46:44 +02:00
void run()
2017-01-18 21:30:23 +01:00
{
this->action();
}
private:
std::function<void()> action;
};