From b4b15a7411d837c100a0e9ea4b14184c134d177c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 27 Jan 2015 09:58:08 +0100 Subject: Don't enlessly block in the eventloop. The job currently finishes synchronously. If we just use the eventloop in waitForFinished that's automatically handled for us. --- common/clientapi.h | 10 ++++------ 1 file 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: // Query all resources and aggregate results // query tells us in which resources we're interested // TODO: queries to individual resources could be parallelized - auto eventloop = QSharedPointer::create(); Async::Job job = Async::null(); for(const QString &resource : query.resources) { 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 + //TODO: we should be able to just do, job = job.then(facade->load(..)) job = job.then([facade, query, addCallback](Async::Future &future) { Async::Job j = facade->load(query, addCallback); j.then([&future, facade](Async::Future &f) { @@ -435,13 +435,11 @@ public: }).exec(); }); } - job.then([eventloop, resultSet](Async::Future &future) { + job.then([/* eventloop, */resultSet](Async::Future &future) { + qDebug() << "Query complete"; resultSet->complete(); - eventloop->quit(); future.setFinished(); - }).exec(); - //The thread contains no eventloop, so execute one here - eventloop->exec(QEventLoop::ExcludeUserInputEvents); + }).exec().waitForFinished(); //We use the eventloop provided by waitForFinished to keep the thread alive until all is done }); return resultSet->emitter(); } -- cgit v1.2.3