Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
|
||||
#include <LtsUtilsCore/ltsutilscore_export.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
||||
class QTimer;
|
||||
|
||||
|
||||
namespace LtsUtils
|
||||
{
|
||||
typedef std::function<void(const QVariant &value)> RawResultFunction;
|
||||
typedef const RawResultFunction &ResultFunction;
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSUTILSCORE_EXPORT Promise : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Promise(const std::function<void(ResultFunction resolve, ResultFunction reject)> &function, QObject *parent = nullptr);
|
||||
|
||||
|
||||
|
||||
void setFunction(const std::function<void(ResultFunction resolve, ResultFunction reject)> &function);
|
||||
|
||||
|
||||
|
||||
void resolve(const QVariant &value = QVariant());
|
||||
|
||||
|
||||
|
||||
void reject(const QVariant &value = QVariant());
|
||||
|
||||
|
||||
|
||||
void setTimeout(int interval);
|
||||
|
||||
|
||||
|
||||
Promise &resolved(ResultFunction resolveFn);
|
||||
|
||||
|
||||
|
||||
Promise &rejected(ResultFunction rejectFn);
|
||||
|
||||
|
||||
private:
|
||||
RawResultFunction m_resolveFn;
|
||||
RawResultFunction m_rejectFn;
|
||||
bool m_functionAlreadySet;
|
||||
QTimer *m_timeout;
|
||||
bool m_resultSet;
|
||||
bool m_timeoutSet;
|
||||
|
||||
|
||||
private slots:
|
||||
void slotTimeout();
|
||||
};
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user