-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvariantpromise.h
33 lines (27 loc) · 975 Bytes
/
variantpromise.h
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
#ifndef VARIANTPROMISE_H
#define VARIANTPROMISE_H
#include <QtCore>
class VariantPromise : public QObject {
Q_OBJECT
public:
explicit VariantPromise(QObject *parent = nullptr) : QObject(parent) {
connect(this, &VariantPromise::resolve, this, &QObject::deleteLater);
connect(this, &VariantPromise::reject, this, &QObject::deleteLater);
};
template <typename Function> VariantPromise &then(Function func) {
connect(this, &VariantPromise::resolve, this, func);
return *this;
}
template <typename Function> VariantPromise &onFailed(Function func) {
connect(this, &VariantPromise::reject, this, func);
return *this;
}
template <typename Function> VariantPromise &finally(Function func) {
connect(this, &VariantPromise::destroyed, this, func);
return *this;
}
signals:
void resolve(QVariant result);
void reject(const QString &message);
};
#endif // VARIANTPROMISE_H