-
Notifications
You must be signed in to change notification settings - Fork 2
/
Promise.hpp
40 lines (32 loc) · 956 Bytes
/
Promise.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef PROMISE_HPP
#define PROMISE_HPP
#include <QObject>
#include <QJSValue>
#include <QVariant>
class QmlPromise : public QObject
{
Q_OBJECT
Q_PROPERTY(bool isFulfilled READ isFulfilled NOTIFY settled)
Q_PROPERTY(bool isRejected READ isRejected NOTIFY settled)
Q_PROPERTY(bool isSettled READ isSettled NOTIFY settled)
QObject* internalPromise;
bool wasFulfilled = false;
bool wasRejected = false;
public:
QmlPromise(QObject* parent);
virtual ~QmlPromise();
bool isFulfilled();
bool isRejected();
bool isSettled();
/// Returns true if the javascript promise was already destroyed; false otherwise
bool wasForgotten() { return internalPromise; }
operator QJSValue();
public slots:
void resolve(QVariant args = QVariant());
void reject(QVariant reason = QVariant());
signals:
void fulfilled(QVariant);
void rejected(QVariant);
void settled();
};
#endif // PROMISE_HPP