summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/clientapi.h25
1 files changed, 10 insertions, 15 deletions
diff --git a/common/clientapi.h b/common/clientapi.h
index f9290af..75a4d24 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -474,30 +474,25 @@ public:
474 //The result provider must be threadsafe. 474 //The result provider must be threadsafe.
475 async::run([resultSet, query](){ 475 async::run([resultSet, query](){
476 // Query all resources and aggregate results 476 // Query all resources and aggregate results
477 // query tells us in which resources we're interested 477 const QList<QByteArray> resources = query.resources;
478 // TODO: queries to individual resources could be parallelized 478 Async::start<QList<QByteArray>>([resources](){return resources;})
479 Async::Job<void> job = Async::null<void>(); 479 .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, Async::Future<void> &future) {
480 for(const QByteArray &resource : query.resources) {
481 auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); 480 auto facade = FacadeFactory::instance().getFacade<DomainType>(resource);
482
483 // TODO The following is a necessary hack to keep the facade alive. 481 // TODO The following is a necessary hack to keep the facade alive.
484 // Otherwise this would reduce to: 482 // Otherwise this would reduce to:
485 // job = job.then(facade->load(query, addCallback)); 483 // facade->load(query, addCallback).exec();
486 // We somehow have to guarantee that the facade remains valid for the duration of the job 484 // We somehow have to guarantee that the facade remains valid for the duration of the job
487 // TODO: Use one result set per facade, and merge the results separately 485 // TODO: Use one result set per facade, and merge the results separately
488 // resultSet->addSubset(facade->query(query)); 486 // resultSet->addSubset(facade->query(query));
489 job = job.then<void>([facade, query, resultSet](Async::Future<void> &future) { 487 facade->load(query, resultSet).template then<void>([&future, facade]() {
490 Async::Job<void> j = facade->load(query, resultSet); 488 future.setFinished();
491 j.then<void>([&future, facade](Async::Future<void> &f) { 489 }).exec();
492 future.setFinished(); 490 }).template then<void>([resultSet]() {
493 f.setFinished();
494 }).exec();
495 });
496 }
497 job.then<void>([resultSet]() {
498 qDebug() << "Query complete"; 491 qDebug() << "Query complete";
499 resultSet->complete(); 492 resultSet->complete();
500 }).exec().waitForFinished(); //We use the eventloop provided by waitForFinished to keep the thread alive until all is done 493 }).exec().waitForFinished(); //We use the eventloop provided by waitForFinished to keep the thread alive until all is done
494 //FIXME for live query the thread dies after the initial query?
495 //TODO associate the thread with the query runner
501 }); 496 });
502 return resultSet->emitter(); 497 return resultSet->emitter();
503 } 498 }