diff options
Diffstat (limited to 'common/clientapi.h')
-rw-r--r-- | common/clientapi.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index aa3aab8..63305ab 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -425,13 +425,22 @@ public: | |||
425 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); | 425 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); |
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. | 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. |
427 | 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); |
428 | //We copy the facade pointer to keep it alive | 428 | |
429 | job = job.then(facade->load(query, addCallback)); | 429 | // TODO The following is a necessary hack to keep the facade alive. |
430 | // Otherwise this would reduce to: | ||
431 | // job = job.then(facade->load(query, addCallback)); | ||
432 | // We somehow have to guarantee that the facade remains valid for the duration of the job | ||
433 | job = job.then<void>([facade, query, addCallback](Async::Future<void> &future) { | ||
434 | Async::Job<void> j = facade->load(query, addCallback); | ||
435 | j.then<void>([&future, facade](Async::Future<void> &f) { | ||
436 | future.setFinished(); | ||
437 | f.setFinished(); | ||
438 | }).exec(); | ||
439 | }); | ||
430 | } | 440 | } |
431 | job.then<void>([/* eventloop, */resultSet](Async::Future<void> &future) { | 441 | job.then<void>([resultSet]() { |
432 | qDebug() << "Query complete"; | 442 | qDebug() << "Query complete"; |
433 | resultSet->complete(); | 443 | resultSet->complete(); |
434 | future.setFinished(); | ||
435 | }).exec().waitForFinished(); //We use the eventloop provided by waitForFinished to keep the thread alive until all is done | 444 | }).exec().waitForFinished(); //We use the eventloop provided by waitForFinished to keep the thread alive until all is done |
436 | }); | 445 | }); |
437 | return resultSet->emitter(); | 446 | return resultSet->emitter(); |