mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
46 lines
771 B
C++
46 lines
771 B
C++
#ifndef ASYNCWORKER_H
|
|
#define ASYNCWORKER_H
|
|
|
|
#include <QThread>
|
|
|
|
#include <QAtomicInt>
|
|
|
|
namespace vnotex
|
|
{
|
|
class AsyncWorker : public QThread
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit AsyncWorker(QObject *p_parent = nullptr);
|
|
|
|
public slots:
|
|
void stop();
|
|
|
|
protected:
|
|
bool isAskedToStop() const;
|
|
|
|
private:
|
|
QAtomicInt m_askedToStop = 0;
|
|
};
|
|
|
|
|
|
class AsyncWorkerWithFunctor : public QThread
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
typedef std::function<void()> Functor;
|
|
|
|
explicit AsyncWorkerWithFunctor(QObject *p_parent = nullptr);
|
|
|
|
void doWork(const Functor &p_functor);
|
|
|
|
protected:
|
|
void run() Q_DECL_OVERRIDE;
|
|
|
|
private:
|
|
Functor m_functor;
|
|
};
|
|
}
|
|
|
|
#endif // ASYNCWORKER_H
|