diff options
-rw-r--r-- | common/synclistresult.h | 65 | ||||
-rw-r--r-- | tests/databasepopulationandfacadequerybenchmark.cpp | 1 | ||||
-rw-r--r-- | tests/pipelinebenchmark.cpp | 1 |
3 files changed, 0 insertions, 67 deletions
diff --git a/common/synclistresult.h b/common/synclistresult.h deleted file mode 100644 index 344c0ef..0000000 --- a/common/synclistresult.h +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <QList> | ||
4 | #include <functional> | ||
5 | #include <QSharedPointer> | ||
6 | #include <QEventLoop> | ||
7 | #include <QDebug> | ||
8 | #include "resultprovider.h" | ||
9 | |||
10 | namespace async { | ||
11 | |||
12 | /* | ||
13 | * A result set specialization that provides a syncronous list. | ||
14 | * | ||
15 | * Only for testing purposes. | ||
16 | * | ||
17 | * WARNING: The nested eventloop can cause all sorts of trouble. Use only in testing code. | ||
18 | */ | ||
19 | template <class T> | ||
20 | class SyncListResult : public QList<T> | ||
21 | { | ||
22 | public: | ||
23 | SyncListResult(const QSharedPointer<Sink::ResultEmitter<T>> &emitter) : QList<T>(), mEmitter(emitter) | ||
24 | { | ||
25 | emitter->onAdded([this](const T &value) { this->append(value); }); | ||
26 | emitter->onModified([this](const T &value) { | ||
27 | for (auto it = this->begin(); it != this->end(); it++) { | ||
28 | if (**it == *value) { | ||
29 | it = this->erase(it); | ||
30 | this->insert(it, value); | ||
31 | break; | ||
32 | } | ||
33 | } | ||
34 | }); | ||
35 | emitter->onRemoved([this](const T &value) { | ||
36 | for (auto it = this->begin(); it != this->end(); it++) { | ||
37 | if (**it == *value) { | ||
38 | this->erase(it); | ||
39 | break; | ||
40 | } | ||
41 | } | ||
42 | }); | ||
43 | emitter->onInitialResultSetComplete([this]() { | ||
44 | if (eventLoopAborter) { | ||
45 | eventLoopAborter(); | ||
46 | // Be safe in case of a second invocation of the complete handler | ||
47 | eventLoopAborter = std::function<void()>(); | ||
48 | } | ||
49 | }); | ||
50 | emitter->onComplete([this]() { mEmitter.clear(); }); | ||
51 | emitter->onClear([this]() { this->clear(); }); | ||
52 | } | ||
53 | |||
54 | void exec() | ||
55 | { | ||
56 | QEventLoop eventLoop; | ||
57 | eventLoopAborter = [&eventLoop]() { eventLoop.quit(); }; | ||
58 | eventLoop.exec(); | ||
59 | } | ||
60 | |||
61 | private: | ||
62 | QSharedPointer<Sink::ResultEmitter<T>> mEmitter; | ||
63 | std::function<void()> eventLoopAborter; | ||
64 | }; | ||
65 | } | ||
diff --git a/tests/databasepopulationandfacadequerybenchmark.cpp b/tests/databasepopulationandfacadequerybenchmark.cpp index 7f478cf..734b00d 100644 --- a/tests/databasepopulationandfacadequerybenchmark.cpp +++ b/tests/databasepopulationandfacadequerybenchmark.cpp | |||
@@ -7,7 +7,6 @@ | |||
7 | #include <common/facade.h> | 7 | #include <common/facade.h> |
8 | #include <common/domainadaptor.h> | 8 | #include <common/domainadaptor.h> |
9 | #include <common/resultprovider.h> | 9 | #include <common/resultprovider.h> |
10 | #include <common/synclistresult.h> | ||
11 | #include <common/definitions.h> | 10 | #include <common/definitions.h> |
12 | #include <common/query.h> | 11 | #include <common/query.h> |
13 | #include <common/store.h> | 12 | #include <common/store.h> |
diff --git a/tests/pipelinebenchmark.cpp b/tests/pipelinebenchmark.cpp index 9262d65..e9713cd 100644 --- a/tests/pipelinebenchmark.cpp +++ b/tests/pipelinebenchmark.cpp | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <common/facade.h> | 26 | #include <common/facade.h> |
27 | #include <common/domainadaptor.h> | 27 | #include <common/domainadaptor.h> |
28 | #include <common/resultprovider.h> | 28 | #include <common/resultprovider.h> |
29 | #include <common/synclistresult.h> | ||
30 | #include <common/definitions.h> | 29 | #include <common/definitions.h> |
31 | #include <common/query.h> | 30 | #include <common/query.h> |
32 | #include <common/store.h> | 31 | #include <common/store.h> |