diff options
-rw-r--r-- | common/clientapi.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index aa3aab8..f015b56 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -425,8 +425,18 @@ 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>([/* eventloop, */resultSet](Async::Future<void> &future) { |
432 | qDebug() << "Query complete"; | 442 | qDebug() << "Query complete"; |