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