diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-04-27 11:19:47 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-04-27 11:19:47 +0200 |
commit | e0a0b6473b87194df89e126c6e68a37560a22d35 (patch) | |
tree | 52648b9a933169db1030965ac63e83bc3ee6244d | |
parent | 0a554aabb94cef6f7c4528534549c2a23514a44e (diff) | |
download | sink-e0a0b6473b87194df89e126c6e68a37560a22d35.tar.gz sink-e0a0b6473b87194df89e126c6e68a37560a22d35.zip |
Make use of Async::iterate
-rw-r--r-- | common/clientapi.h | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index f7f4c13..e1fe001 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -535,22 +535,19 @@ public: | |||
535 | //The result provider must be threadsafe. | 535 | //The result provider must be threadsafe. |
536 | async::run([query, resultSet](){ | 536 | async::run([query, resultSet](){ |
537 | // Query all resources and aggregate results | 537 | // Query all resources and aggregate results |
538 | const QList<QByteArray> resources = query.resources; | 538 | Async::iterate(query.resources) |
539 | { | 539 | .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, Async::Future<void> &future) { |
540 | Async::start<QList<QByteArray>>([resources](){return resources;}) | 540 | //TODO pass resource identifier to factory |
541 | .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, Async::Future<void> &future) { | 541 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); |
542 | //TODO pass resource identifier to factory | 542 | facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec(); |
543 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); | 543 | //Keep the facade alive for the duration for the lifetime of the resultSet. |
544 | facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec(); | 544 | resultSet->setFacade(facade); |
545 | //Keep the facade alive for the duration for the lifetime of the resultSet. | 545 | }).template then<void>([query, resultSet]() { |
546 | resultSet->setFacade(facade); | 546 | resultSet->initialResultSetComplete(); |
547 | }).template then<void>([query, resultSet]() { | 547 | if (!query.liveQuery) { |
548 | resultSet->initialResultSetComplete(); | 548 | resultSet->complete(); |
549 | if (!query.liveQuery) { | 549 | } |
550 | resultSet->complete(); | 550 | }).exec(); |
551 | } | ||
552 | }).exec(); | ||
553 | } | ||
554 | 551 | ||
555 | //Keep the thread alive until the result is ready | 552 | //Keep the thread alive until the result is ready |
556 | if (!resultSet->isDone()) { | 553 | if (!resultSet->isDone()) { |