mirror-chatterino2/asyncexec.h

32 lines
498 B
C
Raw Normal View History

2017-01-04 15:12:31 +01:00
#ifndef ASYNCEXEC_H
#define ASYNCEXEC_H
#include "qcoreapplication.h"
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-01-11 18:52:09 +01:00
#define async_exec(a) \
2017-01-18 21:30:23 +01:00
QThreadPool::globalInstance()->start(new LambdaRunnable(a));
class LambdaRunnable : public QRunnable
{
public:
LambdaRunnable(std::function<void()> action)
{
this->action = action;
}
void
run()
{
this->action();
}
private:
std::function<void()> action;
};
2017-01-04 15:12:31 +01:00
2017-01-11 18:52:09 +01:00
#endif // ASYNCEXEC_H