forked from Cutehacks/duperagent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
promisemodule.h
66 lines (47 loc) · 1.24 KB
/
promisemodule.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2016 Cutehacks AS. All rights reserved.
// License can be found in the LICENSE file.
#ifndef PROMISEMODULE_H
#define PROMISEMODULE_H
#include <QtCore/QObject>
#include <QtQml/QJSValue>
#include "promise.h"
class QQmlEngine;
namespace com { namespace cutehacks { namespace duperagent {
class MultiPromiseExecutor : public QObject {
Q_OBJECT
public:
enum Behavior {
All,
Race
};
explicit MultiPromiseExecutor(QQmlEngine *, Behavior, QObject *parent = 0);
QJSValue self() { return m_self; }
Promise *addIterable(QJSValue);
public slots:
void handlePromise(Promise::State, QJSValue);
protected:
void promiseDone(Promise *);
private:
QQmlEngine *m_engine;
int m_index;
int m_argsLength;
Behavior m_behavior;
QJSValue m_self;
QJSValue m_args;
Promise *m_promise;
};
class PromiseModule : public QObject
{
Q_OBJECT
public:
explicit PromiseModule(QQmlEngine *, QObject *parent = 0);
Q_INVOKABLE QJSValue create(QJSValue);
Q_INVOKABLE QJSValue all(QJSValue);
Q_INVOKABLE QJSValue race(QJSValue);
Q_INVOKABLE QJSValue resolve(QJSValue);
Q_INVOKABLE QJSValue reject(QJSValue);
private:
QQmlEngine *m_engine;
};
} } }
#endif // PROMISEMODULE_H