diff options
Diffstat (limited to 'common/clientapi.h')
-rw-r--r-- | common/clientapi.h | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index 55fbed1..542039e 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -420,13 +420,13 @@ public: | |||
420 | // Query all resources and aggregate results | 420 | // Query all resources and aggregate results |
421 | // query tells us in which resources we're interested | 421 | // query tells us in which resources we're interested |
422 | // TODO: queries to individual resources could be parallelized | 422 | // TODO: queries to individual resources could be parallelized |
423 | auto eventloop = QSharedPointer<QEventLoop>::create(); | ||
424 | Async::Job<void> job = Async::null<void>(); | 423 | Async::Job<void> job = Async::null<void>(); |
425 | for(const QString &resource : query.resources) { | 424 | for(const QString &resource : query.resources) { |
426 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); | 425 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); |
427 | //We have to bind an instance to the function callback. Since we use a shared pointer this keeps the result provider instance (and thus also the emitter) alive. | 426 | //We have to bind an instance to the function callback. Since we use a shared pointer this keeps the result provider instance (and thus also the emitter) alive. |
428 | std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1); | 427 | std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1); |
429 | //We copy the facade pointer to keep it alive | 428 | //We copy the facade pointer to keep it alive |
429 | //TODO: we should be able to just do, job = job.then(facade->load(..)) | ||
430 | job = job.then<void>([facade, query, addCallback](Async::Future<void> &future) { | 430 | job = job.then<void>([facade, query, addCallback](Async::Future<void> &future) { |
431 | Async::Job<void> j = facade->load(query, addCallback); | 431 | Async::Job<void> j = facade->load(query, addCallback); |
432 | j.then<void>([&future, facade](Async::Future<void> &f) { | 432 | j.then<void>([&future, facade](Async::Future<void> &f) { |
@@ -435,13 +435,11 @@ public: | |||
435 | }).exec(); | 435 | }).exec(); |
436 | }); | 436 | }); |
437 | } | 437 | } |
438 | job.then<void>([eventloop, resultSet](Async::Future<void> &future) { | 438 | job.then<void>([/* eventloop, */resultSet](Async::Future<void> &future) { |
439 | qDebug() << "Query complete"; | ||
439 | resultSet->complete(); | 440 | resultSet->complete(); |
440 | eventloop->quit(); | ||
441 | future.setFinished(); | 441 | future.setFinished(); |
442 | }).exec(); | 442 | }).exec().waitForFinished(); //We use the eventloop provided by waitForFinished to keep the thread alive until all is done |
443 | //The thread contains no eventloop, so execute one here | ||
444 | eventloop->exec(QEventLoop::ExcludeUserInputEvents); | ||
445 | }); | 443 | }); |
446 | return resultSet->emitter(); | 444 | return resultSet->emitter(); |
447 | } | 445 | } |