diff options
Diffstat (limited to 'common/genericresource.cpp')
-rw-r--r-- | common/genericresource.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 4dd73b3..734c1b5 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp | |||
@@ -198,27 +198,26 @@ void GenericResource::processCommand(int commandId, const QByteArray &data) | |||
198 | enqueueCommand(mUserQueue, commandId, data); | 198 | enqueueCommand(mUserQueue, commandId, data); |
199 | } | 199 | } |
200 | 200 | ||
201 | static void waitForDrained(KAsync::Future<void> &f, MessageQueue &queue) | ||
202 | { | ||
203 | if (queue.isEmpty()) { | ||
204 | f.setFinished(); | ||
205 | } else { | ||
206 | QObject::connect(&queue, &MessageQueue::drained, [&f]() { | ||
207 | f.setFinished(); | ||
208 | }); | ||
209 | } | ||
210 | }; | ||
211 | |||
201 | KAsync::Job<void> GenericResource::processAllMessages() | 212 | KAsync::Job<void> GenericResource::processAllMessages() |
202 | { | 213 | { |
203 | //We have to wait for all items to be processed to ensure the synced items are available when a query gets executed. | 214 | //We have to wait for all items to be processed to ensure the synced items are available when a query gets executed. |
204 | //TODO: report errors while processing sync? | 215 | //TODO: report errors while processing sync? |
205 | //TODO JOBAPI: A helper that waits for n events and then continues? | 216 | //TODO JOBAPI: A helper that waits for n events and then continues? |
206 | return KAsync::start<void>([this](KAsync::Future<void> &f) { | 217 | return KAsync::start<void>([this](KAsync::Future<void> &f) { |
207 | if (mSynchronizerQueue.isEmpty()) { | 218 | waitForDrained(f, mSynchronizerQueue); |
208 | f.setFinished(); | ||
209 | } else { | ||
210 | QObject::connect(&mSynchronizerQueue, &MessageQueue::drained, [&f]() { | ||
211 | f.setFinished(); | ||
212 | }); | ||
213 | } | ||
214 | }).then<void>([this](KAsync::Future<void> &f) { | 219 | }).then<void>([this](KAsync::Future<void> &f) { |
215 | if (mUserQueue.isEmpty()) { | 220 | waitForDrained(f, mUserQueue); |
216 | f.setFinished(); | ||
217 | } else { | ||
218 | QObject::connect(&mUserQueue, &MessageQueue::drained, [&f]() { | ||
219 | f.setFinished(); | ||
220 | }); | ||
221 | } | ||
222 | }); | 221 | }); |
223 | } | 222 | } |
224 | 223 | ||