From 8f08814b58f820a38c1de0c530cab55ea47ad960 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 19 Apr 2015 12:27:22 +0200 Subject: Async refactoring in clientapi using each executor --- common/clientapi.h | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/common/clientapi.h b/common/clientapi.h index f9290af..75a4d24 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -474,30 +474,25 @@ public: //The result provider must be threadsafe. async::run([resultSet, query](){ // Query all resources and aggregate results - // query tells us in which resources we're interested - // TODO: queries to individual resources could be parallelized - Async::Job job = Async::null(); - for(const QByteArray &resource : query.resources) { + const QList resources = query.resources; + Async::start>([resources](){return resources;}) + .template each([query, resultSet](const QByteArray &resource, Async::Future &future) { auto facade = FacadeFactory::instance().getFacade(resource); - // TODO The following is a necessary hack to keep the facade alive. // Otherwise this would reduce to: - // job = job.then(facade->load(query, addCallback)); + // facade->load(query, addCallback).exec(); // We somehow have to guarantee that the facade remains valid for the duration of the job // TODO: Use one result set per facade, and merge the results separately // resultSet->addSubset(facade->query(query)); - job = job.then([facade, query, resultSet](Async::Future &future) { - Async::Job j = facade->load(query, resultSet); - j.then([&future, facade](Async::Future &f) { - future.setFinished(); - f.setFinished(); - }).exec(); - }); - } - job.then([resultSet]() { + facade->load(query, resultSet).template then([&future, facade]() { + future.setFinished(); + }).exec(); + }).template then([resultSet]() { qDebug() << "Query complete"; resultSet->complete(); }).exec().waitForFinished(); //We use the eventloop provided by waitForFinished to keep the thread alive until all is done + //FIXME for live query the thread dies after the initial query? + //TODO associate the thread with the query runner }); return resultSet->emitter(); } -- cgit v1.2.3