-
Notifications
You must be signed in to change notification settings - Fork 16
/
promise.h
47 lines (40 loc) · 1.28 KB
/
promise.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef PROMISE_H
#define PROMISE_H
#include <QObject>
#include <QVariant>
#include <QVariantMap>
class Promise : public QObject
{
Q_OBJECT
public:
static Promise* all(QList<Promise*>, QObject *parent = 0);
static Promise* some(QList<Promise*>, QObject *parent = 0);
enum State{
pending,
success,
failure
};
typedef std::function<Promise*(const QVariant&)> Monad;
explicit Promise(QObject *parent = 0);
State state();
Promise* pipe(const Monad&, const Monad&);
Promise* pipe(const Monad&);
Promise* then(const std::function<void(const QVariant&)>&);
Promise* then(const std::function<void(const QVariant&)>&, const std::function<void(const QVariant&)>&);
Promise* then(const std::function<void(const QVariant&)>&, const std::function<void(const QVariant&)>&, const std::function<void(const QVariant&)>&);
// then (done, fail, progress)
signals:
void done(const QVariant&);
void fail(const QVariant&);
void progress(const QVariant&);
public slots:
Promise* resolve(const QVariant& = QVariant());
Promise* reject(const QVariant& = QVariant());
Promise* advance(const QVariant& = QVariant());
private:
State s;
int tasksCount;
QVariantList datas;
QVariant data;
};
#endif // PROMISE_H