From 4707e725cefbf58b9f66c860680e94e6bdb9001f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 2 Apr 2015 17:16:47 +0200 Subject: Unbreak the clientapi. We indeed have to keep the facade alive, otherwise this starts crashing. --- common/clientapi.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'common') 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: auto facade = FacadeFactory::instance().getFacade(resource); //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. std::function addCallback = std::bind(&ResultProvider::add, resultSet, std::placeholders::_1); - //We copy the facade pointer to keep it alive - job = job.then(facade->load(query, addCallback)); + + // TODO The following is a necessary hack to keep the facade alive. + // Otherwise this would reduce to: + // job = job.then(facade->load(query, addCallback)); + // We somehow have to guarantee that the facade remains valid for the duration of the job + job = job.then([facade, query, addCallback](Async::Future &future) { + Async::Job j = facade->load(query, addCallback); + j.then([&future, facade](Async::Future &f) { + future.setFinished(); + f.setFinished(); + }).exec(); + }); } job.then([/* eventloop, */resultSet](Async::Future &future) { qDebug() << "Query complete"; -- cgit v1.2.3