summaryrefslogtreecommitdiffstats
path: root/async/src/async.h
diff options
context:
space:
mode:
Diffstat (limited to 'async/src/async.h')
-rw-r--r--async/src/async.h134
1 files changed, 68 insertions, 66 deletions
diff --git a/async/src/async.h b/async/src/async.h
index b1f1121..152f98e 100644
--- a/async/src/async.h
+++ b/async/src/async.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2014 Daniel Vrátil <dvratil@redhat.com> 2 * Copyright 2014 - 2015 Daniel Vrátil <dvratil@redhat.com>
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public License as 5 * modify it under the terms of the GNU Library General Public License as
@@ -15,8 +15,10 @@
15 * along with this library. If not, see <http://www.gnu.org/licenses/>. 15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18#ifndef ASYNC_H 18#ifndef KASYNC_H
19#define ASYNC_H 19#define KASYNC_H
20
21#include "kasync_export.h"
20 22
21#include <functional> 23#include <functional>
22#include <list> 24#include <list>
@@ -64,7 +66,7 @@
64 * TODO: Possibility to abort a job through future (perhaps optional?) 66 * TODO: Possibility to abort a job through future (perhaps optional?)
65 * TODO: Support for timeout, specified during exec call, after which the error handler gets called with a defined errorCode. 67 * TODO: Support for timeout, specified during exec call, after which the error handler gets called with a defined errorCode.
66 */ 68 */
67namespace Async { 69namespace KAsync {
68 70
69template<typename PrevOut, typename Out, typename ... In> 71template<typename PrevOut, typename Out, typename ... In>
70class Executor; 72class Executor;
@@ -75,15 +77,15 @@ template<typename Out, typename ... In>
75class Job; 77class Job;
76 78
77template<typename Out, typename ... In> 79template<typename Out, typename ... In>
78using ThenTask = typename detail::identity<std::function<void(In ..., Async::Future<Out>&)>>::type; 80using ThenTask = typename detail::identity<std::function<void(In ..., KAsync::Future<Out>&)>>::type;
79template<typename Out, typename ... In> 81template<typename Out, typename ... In>
80using SyncThenTask = typename detail::identity<std::function<Out(In ...)>>::type; 82using SyncThenTask = typename detail::identity<std::function<Out(In ...)>>::type;
81template<typename Out, typename In> 83template<typename Out, typename In>
82using EachTask = typename detail::identity<std::function<void(In, Async::Future<Out>&)>>::type; 84using EachTask = typename detail::identity<std::function<void(In, KAsync::Future<Out>&)>>::type;
83template<typename Out, typename In> 85template<typename Out, typename In>
84using SyncEachTask = typename detail::identity<std::function<Out(In)>>::type; 86using SyncEachTask = typename detail::identity<std::function<Out(In)>>::type;
85template<typename Out, typename In> 87template<typename Out, typename In>
86using ReduceTask = typename detail::identity<std::function<void(In, Async::Future<Out>&)>>::type; 88using ReduceTask = typename detail::identity<std::function<void(In, KAsync::Future<Out>&)>>::type;
87template<typename Out, typename In> 89template<typename Out, typename In>
88using SyncReduceTask = typename detail::identity<std::function<Out(In)>>::type; 90using SyncReduceTask = typename detail::identity<std::function<Out(In)>>::type;
89 91
@@ -96,15 +98,15 @@ namespace Private
96class ExecutorBase; 98class ExecutorBase;
97typedef QSharedPointer<ExecutorBase> ExecutorBasePtr; 99typedef QSharedPointer<ExecutorBase> ExecutorBasePtr;
98 100
99struct Execution { 101struct KASYNC_EXPORT Execution {
100 Execution(const ExecutorBasePtr &executor); 102 Execution(const ExecutorBasePtr &executor);
101 ~Execution(); 103 ~Execution();
102 void setFinished(); 104 void setFinished();
103 105
104 template<typename T> 106 template<typename T>
105 Async::Future<T>* result() const 107 KAsync::Future<T>* result() const
106 { 108 {
107 return static_cast<Async::Future<T>*>(resultBase); 109 return static_cast<KAsync::Future<T>*>(resultBase);
108 } 110 }
109 111
110 void releaseFuture(); 112 void releaseFuture();
@@ -125,16 +127,16 @@ struct Execution {
125 127
126typedef QSharedPointer<Execution> ExecutionPtr; 128typedef QSharedPointer<Execution> ExecutionPtr;
127 129
128class ExecutorBase 130class KASYNC_EXPORT ExecutorBase
129{ 131{
130 template<typename PrevOut, typename Out, typename ... In> 132 template<typename PrevOut, typename Out, typename ... In>
131 friend class Executor; 133 friend class Executor;
132 134
133 template<typename Out, typename ... In> 135 template<typename Out, typename ... In>
134 friend class Async::Job; 136 friend class KAsync::Job;
135 137
136 friend class Execution; 138 friend class Execution;
137 friend class Async::Tracer; 139 friend class KAsync::Tracer;
138 140
139public: 141public:
140 virtual ~ExecutorBase(); 142 virtual ~ExecutorBase();
@@ -144,7 +146,7 @@ protected:
144 ExecutorBase(const ExecutorBasePtr &parent); 146 ExecutorBase(const ExecutorBasePtr &parent);
145 147
146 template<typename T> 148 template<typename T>
147 Async::Future<T>* createFuture(const ExecutionPtr &execution) const; 149 KAsync::Future<T>* createFuture(const ExecutionPtr &execution) const;
148 150
149 virtual bool hasErrorFunc() const = 0; 151 virtual bool hasErrorFunc() const = 0;
150 virtual bool handleError(const ExecutionPtr &execution) = 0; 152 virtual bool handleError(const ExecutionPtr &execution) = 0;
@@ -193,7 +195,7 @@ public:
193 void run(const ExecutionPtr &execution); 195 void run(const ExecutionPtr &execution);
194private: 196private:
195 EachTask<Out, In> mFunc; 197 EachTask<Out, In> mFunc;
196 QVector<Async::FutureWatcher<Out>*> mFutureWatchers; 198 QVector<KAsync::FutureWatcher<Out>*> mFutureWatchers;
197}; 199};
198 200
199template<typename Out, typename In> 201template<typename Out, typename In>
@@ -234,8 +236,8 @@ public:
234 SyncEachExecutor(SyncEachTask<Out, In> each, ErrorHandler errorFunc, const ExecutorBasePtr &parent); 236 SyncEachExecutor(SyncEachTask<Out, In> each, ErrorHandler errorFunc, const ExecutorBasePtr &parent);
235 void run(const ExecutionPtr &execution); 237 void run(const ExecutionPtr &execution);
236private: 238private:
237 void run(Async::Future<Out> *future, const typename PrevOut::value_type &arg, std::false_type); // !std::is_void<Out> 239 void run(KAsync::Future<Out> *future, const typename PrevOut::value_type &arg, std::false_type); // !std::is_void<Out>
238 void run(Async::Future<Out> *future, const typename PrevOut::value_type &arg, std::true_type); // std::is_void<Out> 240 void run(KAsync::Future<Out> *future, const typename PrevOut::value_type &arg, std::true_type); // std::is_void<Out>
239 SyncEachTask<Out, In> mFunc; 241 SyncEachTask<Out, In> mFunc;
240}; 242};
241 243
@@ -244,11 +246,11 @@ private:
244/** 246/**
245 * Start an asynchronous job sequence. 247 * Start an asynchronous job sequence.
246 * 248 *
247 * Async::start() is your starting point to build a chain of jobs to be executed 249 * KAsync::start() is your starting point to build a chain of jobs to be executed
248 * asynchronously. 250 * asynchronously.
249 * 251 *
250 * @param func An asynchronous function to be executed. The function must have 252 * @param func An asynchronous function to be executed. The function must have
251 * void return type, and accept exactly one argument of type @p Async::Future<In>, 253 * void return type, and accept exactly one argument of type @p KAsync::Future<In>,
252 * where @p In is type of the result. 254 * where @p In is type of the result.
253 */ 255 */
254template<typename Out, typename ... In> 256template<typename Out, typename ... In>
@@ -267,14 +269,14 @@ Job<ReturnType, Args ...> start();
267 * 269 *
268 * The loop continues while @param condition returns true. 270 * The loop continues while @param condition returns true.
269 */ 271 */
270Job<void> dowhile(Condition condition, ThenTask<void> func); 272KASYNC_EXPORT Job<void> dowhile(Condition condition, ThenTask<void> func);
271 273
272/** 274/**
273 * Async while loop. 275 * Async while loop.
274 * 276 *
275 * Loop continues while body returns true. 277 * Loop continues while body returns true.
276 */ 278 */
277Job<void> dowhile(ThenTask<bool> body); 279KASYNC_EXPORT Job<void> dowhile(ThenTask<bool> body);
278 280
279/** 281/**
280 * Iterate over a container. 282 * Iterate over a container.
@@ -287,7 +289,7 @@ Job<Out> iterate(const Out &container);
287/** 289/**
288 * Async delay. 290 * Async delay.
289 */ 291 */
290Job<void> wait(int delay); 292KASYNC_EXPORT Job<void> wait(int delay);
291 293
292/** 294/**
293 * A null job. 295 * A null job.
@@ -307,7 +309,7 @@ Job<Out> null();
307template<typename Out> 309template<typename Out>
308Job<Out> error(int errorCode = 1, const QString &errorMessage = QString()); 310Job<Out> error(int errorCode = 1, const QString &errorMessage = QString());
309 311
310class JobBase 312class KASYNC_EXPORT JobBase
311{ 313{
312 template<typename Out, typename ... In> 314 template<typename Out, typename ... In>
313 friend class Job; 315 friend class Job;
@@ -324,18 +326,18 @@ protected:
324 * An Asynchronous job 326 * An Asynchronous job
325 * 327 *
326 * A single instance of Job represents a single method that will be executed 328 * A single instance of Job represents a single method that will be executed
327 * asynchrously. The Job is started by @p Job::exec(), which returns @p Async::Future 329 * asynchrously. The Job is started by @p Job::exec(), which returns @p KAsync::Future
328 * immediatelly. The Future will be set to finished state once the asynchronous 330 * immediatelly. The Future will be set to finished state once the asynchronous
329 * task has finished. You can use @p Async::Future::waitForFinished() to wait for 331 * task has finished. You can use @p KAsync::Future::waitForFinished() to wait for
330 * for the Future in blocking manner. 332 * for the Future in blocking manner.
331 * 333 *
332 * It is possible to chain multiple Jobs one after another in different fashion 334 * It is possible to chain multiple Jobs one after another in different fashion
333 * (sequential, parallel, etc.). Calling Job::exec() will then return a pending 335 * (sequential, parallel, etc.). Calling Job::exec() will then return a pending
334 * @p Async::Future, and will execute the entire chain of jobs. 336 * @p KAsync::Future, and will execute the entire chain of jobs.
335 * 337 *
336 * @code 338 * @code
337 * auto job = Job::start<QList<int>>( 339 * auto job = Job::start<QList<int>>(
338 * [](Async::Future<QList<int>> &future) { 340 * [](KAsync::Future<QList<int>> &future) {
339 * MyREST::PendingUsers *pu = MyREST::requestListOfUsers(); 341 * MyREST::PendingUsers *pu = MyREST::requestListOfUsers();
340 * QObject::connect(pu, &PendingOperation::finished, 342 * QObject::connect(pu, &PendingOperation::finished,
341 * [&](PendingOperation *pu) { 343 * [&](PendingOperation *pu) {
@@ -344,7 +346,7 @@ protected:
344 * }); 346 * });
345 * }) 347 * })
346 * .each<QList<MyREST::User>, int>( 348 * .each<QList<MyREST::User>, int>(
347 * [](const int &userId, Async::Future<QList<MyREST::User>> &future) { 349 * [](const int &userId, KAsync::Future<QList<MyREST::User>> &future) {
348 * MyREST::PendingUser *pu = MyREST::requestUserDetails(userId); 350 * MyREST::PendingUser *pu = MyREST::requestUserDetails(userId);
349 * QObject::connect(pu, &PendingOperation::finished, 351 * QObject::connect(pu, &PendingOperation::finished,
350 * [&](PendingOperation *pu) { 352 * [&](PendingOperation *pu) {
@@ -353,7 +355,7 @@ protected:
353 * }); 355 * });
354 * }); 356 * });
355 * 357 *
356 * Async::Future<QList<MyREST::User>> usersFuture = job.exec(); 358 * KAsync::Future<QList<MyREST::User>> usersFuture = job.exec();
357 * usersFuture.waitForFinished(); 359 * usersFuture.waitForFinished();
358 * QList<MyRest::User> users = usersFuture.value(); 360 * QList<MyRest::User> users = usersFuture.value();
359 * @endcode 361 * @endcode
@@ -369,10 +371,10 @@ class Job : public JobBase
369 friend class Job; 371 friend class Job;
370 372
371 template<typename OutOther, typename ... InOther> 373 template<typename OutOther, typename ... InOther>
372 friend Job<OutOther, InOther ...> start(Async::ThenTask<OutOther, InOther ...> func, ErrorHandler errorFunc); 374 friend Job<OutOther, InOther ...> start(KAsync::ThenTask<OutOther, InOther ...> func, ErrorHandler errorFunc);
373 375
374 template<typename OutOther, typename ... InOther> 376 template<typename OutOther, typename ... InOther>
375 friend Job<OutOther, InOther ...> start(Async::SyncThenTask<OutOther, InOther ...> func, ErrorHandler errorFunc); 377 friend Job<OutOther, InOther ...> start(KAsync::SyncThenTask<OutOther, InOther ...> func, ErrorHandler errorFunc);
376 378
377#ifdef WITH_KJOB 379#ifdef WITH_KJOB
378 template<typename ReturnType, typename KJobType, ReturnType (KJobType::*KJobResultMethod)(), typename ... Args> 380 template<typename ReturnType, typename KJobType, ReturnType (KJobType::*KJobResultMethod)(), typename ... Args>
@@ -454,7 +456,7 @@ public:
454 } 456 }
455 457
456 template<typename FirstIn> 458 template<typename FirstIn>
457 Async::Future<Out> exec(FirstIn in) 459 KAsync::Future<Out> exec(FirstIn in)
458 { 460 {
459 // Inject a fake sync executor that will return the initial value 461 // Inject a fake sync executor that will return the initial value
460 Private::ExecutorBasePtr first = mExecutor; 462 Private::ExecutorBasePtr first = mExecutor;
@@ -474,10 +476,10 @@ public:
474 return result; 476 return result;
475 } 477 }
476 478
477 Async::Future<Out> exec() 479 KAsync::Future<Out> exec()
478 { 480 {
479 Private::ExecutionPtr execution = mExecutor->exec(mExecutor); 481 Private::ExecutionPtr execution = mExecutor->exec(mExecutor);
480 Async::Future<Out> result = *execution->result<Out>(); 482 KAsync::Future<Out> result = *execution->result<Out>();
481 483
482 return result; 484 return result;
483 } 485 }
@@ -499,15 +501,15 @@ private:
499 template<typename InOther> 501 template<typename InOther>
500 void reduceInvariants() 502 void reduceInvariants()
501 { 503 {
502 static_assert(Async::detail::isIterable<Out>::value, 504 static_assert(KAsync::detail::isIterable<Out>::value,
503 "The 'Result' task can only be connected to a job that returns a list or an array"); 505 "The 'Result' task can only be connected to a job that returns a list or an array");
504 static_assert(std::is_same<typename Out::value_type, typename InOther::value_type>::value, 506 static_assert(std::is_same<typename Out::value_type, typename InOther::value_type>::value,
505 "The return type of previous task must be compatible with input type of this task"); 507 "The return type of previous task must be compatible with input type of this task");
506 } 508 }
507 509
508 template<typename OutOther, typename ... InOther> 510 template<typename OutOther, typename ... InOther>
509 inline std::function<void(InOther ..., Async::Future<OutOther>&)> nestedJobWrapper(Job<OutOther, InOther ...> otherJob) { 511 inline std::function<void(InOther ..., KAsync::Future<OutOther>&)> nestedJobWrapper(Job<OutOther, InOther ...> otherJob) {
510 return [otherJob](InOther ... in, Async::Future<OutOther> &future) { 512 return [otherJob](InOther ... in, KAsync::Future<OutOther> &future) {
511 // copy by value is const 513 // copy by value is const
512 auto job = otherJob; 514 auto job = otherJob;
513 FutureWatcher<OutOther> *watcher = new FutureWatcher<OutOther>(); 515 FutureWatcher<OutOther> *watcher = new FutureWatcher<OutOther>();
@@ -518,7 +520,7 @@ private:
518 // in copyFutureValue() 520 // in copyFutureValue()
519 // copy by value is const 521 // copy by value is const
520 auto outFuture = future; 522 auto outFuture = future;
521 Async::detail::copyFutureValue(watcher->future(), outFuture); 523 KAsync::detail::copyFutureValue(watcher->future(), outFuture);
522 if (watcher->future().errorCode()) { 524 if (watcher->future().errorCode()) {
523 outFuture.setError(watcher->future().errorCode(), watcher->future().errorMessage()); 525 outFuture.setError(watcher->future().errorCode(), watcher->future().errorMessage());
524 } else { 526 } else {
@@ -531,12 +533,12 @@ private:
531 } 533 }
532}; 534};
533 535
534} // namespace Async 536} // namespace KAsync
535 537
536 538
537// ********** Out of line definitions **************** 539// ********** Out of line definitions ****************
538 540
539namespace Async { 541namespace KAsync {
540 542
541template<typename Out, typename ... In> 543template<typename Out, typename ... In>
542Job<Out, In ...> start(ThenTask<Out, In ...> func, ErrorHandler error) 544Job<Out, In ...> start(ThenTask<Out, In ...> func, ErrorHandler error)
@@ -557,7 +559,7 @@ template<typename ReturnType, typename KJobType, ReturnType (KJobType::*KJobResu
557Job<ReturnType, Args ...> start() 559Job<ReturnType, Args ...> start()
558{ 560{
559 return Job<ReturnType, Args ...>(Private::ExecutorBasePtr( 561 return Job<ReturnType, Args ...>(Private::ExecutorBasePtr(
560 new Private::ThenExecutor<ReturnType, Args ...>([](const Args & ... args, Async::Future<ReturnType> &future) 562 new Private::ThenExecutor<ReturnType, Args ...>([](const Args & ... args, KAsync::Future<ReturnType> &future)
561 { 563 {
562 KJobType *job = new KJobType(args ...); 564 KJobType *job = new KJobType(args ...);
563 job->connect(job, &KJob::finished, 565 job->connect(job, &KJob::finished,
@@ -578,8 +580,8 @@ Job<ReturnType, Args ...> start()
578template<typename Out> 580template<typename Out>
579Job<Out> null() 581Job<Out> null()
580{ 582{
581 return Async::start<Out>( 583 return KAsync::start<Out>(
582 [](Async::Future<Out> &future) { 584 [](KAsync::Future<Out> &future) {
583 future.setFinished(); 585 future.setFinished();
584 }); 586 });
585} 587}
@@ -587,8 +589,8 @@ Job<Out> null()
587template<typename Out> 589template<typename Out>
588Job<Out> error(int errorCode, const QString &errorMessage) 590Job<Out> error(int errorCode, const QString &errorMessage)
589{ 591{
590 return Async::start<Out>( 592 return KAsync::start<Out>(
591 [errorCode, errorMessage](Async::Future<Out> &future) { 593 [errorCode, errorMessage](KAsync::Future<Out> &future) {
592 future.setError(errorCode, errorMessage); 594 future.setError(errorCode, errorMessage);
593 }); 595 });
594} 596}
@@ -596,7 +598,7 @@ Job<Out> error(int errorCode, const QString &errorMessage)
596template<typename Out> 598template<typename Out>
597Job<Out> iterate(const Out &container) 599Job<Out> iterate(const Out &container)
598{ 600{
599 return Async::start<Out>( 601 return KAsync::start<Out>(
600 [container]() { 602 [container]() {
601 return container; 603 return container;
602 }); 604 });
@@ -606,9 +608,9 @@ Job<Out> iterate(const Out &container)
606namespace Private { 608namespace Private {
607 609
608template<typename T> 610template<typename T>
609Async::Future<T>* ExecutorBase::createFuture(const ExecutionPtr &execution) const 611KAsync::Future<T>* ExecutorBase::createFuture(const ExecutionPtr &execution) const
610{ 612{
611 return new Async::Future<T>(execution); 613 return new KAsync::Future<T>(execution);
612} 614}
613 615
614template<typename PrevOut, typename Out, typename ... In> 616template<typename PrevOut, typename Out, typename ... In>
@@ -625,8 +627,8 @@ ExecutionPtr Executor<PrevOut, Out, In ...>::exec(const ExecutorBasePtr &self)
625 execution->prevExecution = mPrev ? mPrev->exec(mPrev) : ExecutionPtr(); 627 execution->prevExecution = mPrev ? mPrev->exec(mPrev) : ExecutionPtr();
626 628
627 execution->resultBase = ExecutorBase::createFuture<Out>(execution); 629 execution->resultBase = ExecutorBase::createFuture<Out>(execution);
628 auto fw = new Async::FutureWatcher<Out>(); 630 auto fw = new KAsync::FutureWatcher<Out>();
629 QObject::connect(fw, &Async::FutureWatcher<Out>::futureReady, 631 QObject::connect(fw, &KAsync::FutureWatcher<Out>::futureReady,
630 [fw, execution, this]() { 632 [fw, execution, this]() {
631 handleError(execution); 633 handleError(execution);
632 execution->setFinished(); 634 execution->setFinished();
@@ -634,7 +636,7 @@ ExecutionPtr Executor<PrevOut, Out, In ...>::exec(const ExecutorBasePtr &self)
634 }); 636 });
635 fw->setFuture(*execution->result<Out>()); 637 fw->setFuture(*execution->result<Out>());
636 638
637 Async::Future<PrevOut> *prevFuture = execution->prevExecution ? execution->prevExecution->result<PrevOut>() : nullptr; 639 KAsync::Future<PrevOut> *prevFuture = execution->prevExecution ? execution->prevExecution->result<PrevOut>() : nullptr;
638 if (!prevFuture || prevFuture->isFinished()) { 640 if (!prevFuture || prevFuture->isFinished()) {
639 if (prevFuture) { // prevFuture implies execution->prevExecution 641 if (prevFuture) { // prevFuture implies execution->prevExecution
640 if (prevFuture->errorCode()) { 642 if (prevFuture->errorCode()) {
@@ -655,8 +657,8 @@ ExecutionPtr Executor<PrevOut, Out, In ...>::exec(const ExecutorBasePtr &self)
655 execution->isRunning = true; 657 execution->isRunning = true;
656 run(execution); 658 run(execution);
657 } else { 659 } else {
658 auto prevFutureWatcher = new Async::FutureWatcher<PrevOut>(); 660 auto prevFutureWatcher = new KAsync::FutureWatcher<PrevOut>();
659 QObject::connect(prevFutureWatcher, &Async::FutureWatcher<PrevOut>::futureReady, 661 QObject::connect(prevFutureWatcher, &KAsync::FutureWatcher<PrevOut>::futureReady,
660 [prevFutureWatcher, execution, this]() { 662 [prevFutureWatcher, execution, this]() {
661 auto prevFuture = prevFutureWatcher->future(); 663 auto prevFuture = prevFutureWatcher->future();
662 assert(prevFuture.isFinished()); 664 assert(prevFuture.isFinished());
@@ -679,7 +681,7 @@ ExecutionPtr Executor<PrevOut, Out, In ...>::exec(const ExecutorBasePtr &self)
679 run(execution); 681 run(execution);
680 }); 682 });
681 683
682 prevFutureWatcher->setFuture(*static_cast<Async::Future<PrevOut>*>(prevFuture)); 684 prevFutureWatcher->setFuture(*static_cast<KAsync::Future<PrevOut>*>(prevFuture));
683 } 685 }
684 686
685 return execution; 687 return execution;
@@ -712,7 +714,7 @@ ThenExecutor<Out, In ...>::ThenExecutor(ThenTask<Out, In ...> then, ErrorHandler
712template<typename Out, typename ... In> 714template<typename Out, typename ... In>
713void ThenExecutor<Out, In ...>::run(const ExecutionPtr &execution) 715void ThenExecutor<Out, In ...>::run(const ExecutionPtr &execution)
714{ 716{
715 Async::Future<typename detail::prevOut<In ...>::type> *prevFuture = nullptr; 717 KAsync::Future<typename detail::prevOut<In ...>::type> *prevFuture = nullptr;
716 if (execution->prevExecution) { 718 if (execution->prevExecution) {
717 prevFuture = execution->prevExecution->result<typename detail::prevOut<In ...>::type>(); 719 prevFuture = execution->prevExecution->result<typename detail::prevOut<In ...>::type>();
718 assert(prevFuture->isFinished()); 720 assert(prevFuture->isFinished());
@@ -744,17 +746,17 @@ void EachExecutor<PrevOut, Out, In>::run(const ExecutionPtr &execution)
744 746
745 for (auto arg : prevFuture->value()) { 747 for (auto arg : prevFuture->value()) {
746 //We have to manually manage the lifetime of these temporary futures 748 //We have to manually manage the lifetime of these temporary futures
747 Async::Future<Out> *future = new Async::Future<Out>(); 749 KAsync::Future<Out> *future = new KAsync::Future<Out>();
748 EachExecutor<PrevOut, Out, In>::mFunc(arg, *future); 750 EachExecutor<PrevOut, Out, In>::mFunc(arg, *future);
749 auto fw = new Async::FutureWatcher<Out>(); 751 auto fw = new KAsync::FutureWatcher<Out>();
750 mFutureWatchers.append(fw); 752 mFutureWatchers.append(fw);
751 QObject::connect(fw, &Async::FutureWatcher<Out>::futureReady, 753 QObject::connect(fw, &KAsync::FutureWatcher<Out>::futureReady,
752 [out, fw, this, future]() { 754 [out, fw, this, future]() {
753 assert(fw->future().isFinished()); 755 assert(fw->future().isFinished());
754 const int index = mFutureWatchers.indexOf(fw); 756 const int index = mFutureWatchers.indexOf(fw);
755 assert(index > -1); 757 assert(index > -1);
756 mFutureWatchers.removeAt(index); 758 mFutureWatchers.removeAt(index);
757 Async::detail::aggregateFutureValue<Out>(fw->future(), *out); 759 KAsync::detail::aggregateFutureValue<Out>(fw->future(), *out);
758 if (mFutureWatchers.isEmpty()) { 760 if (mFutureWatchers.isEmpty()) {
759 out->setFinished(); 761 out->setFinished();
760 } 762 }
@@ -794,19 +796,19 @@ void SyncThenExecutor<Out, In ...>::run(const ExecutionPtr &execution)
794template<typename Out, typename ... In> 796template<typename Out, typename ... In>
795void SyncThenExecutor<Out, In ...>::run(const ExecutionPtr &execution, std::false_type) 797void SyncThenExecutor<Out, In ...>::run(const ExecutionPtr &execution, std::false_type)
796{ 798{
797 Async::Future<typename detail::prevOut<In ...>::type> *prevFuture = 799 KAsync::Future<typename detail::prevOut<In ...>::type> *prevFuture =
798 execution->prevExecution 800 execution->prevExecution
799 ? execution->prevExecution->result<typename detail::prevOut<In ...>::type>() 801 ? execution->prevExecution->result<typename detail::prevOut<In ...>::type>()
800 : nullptr; 802 : nullptr;
801 (void) prevFuture; // silence 'set but not used' warning 803 (void) prevFuture; // silence 'set but not used' warning
802 Async::Future<Out> *future = execution->result<Out>(); 804 KAsync::Future<Out> *future = execution->result<Out>();
803 future->setValue(SyncThenExecutor<Out, In...>::mFunc(prevFuture ? prevFuture->value() : In() ...)); 805 future->setValue(SyncThenExecutor<Out, In...>::mFunc(prevFuture ? prevFuture->value() : In() ...));
804} 806}
805 807
806template<typename Out, typename ... In> 808template<typename Out, typename ... In>
807void SyncThenExecutor<Out, In ...>::run(const ExecutionPtr &execution, std::true_type) 809void SyncThenExecutor<Out, In ...>::run(const ExecutionPtr &execution, std::true_type)
808{ 810{
809 Async::Future<typename detail::prevOut<In ...>::type> *prevFuture = 811 KAsync::Future<typename detail::prevOut<In ...>::type> *prevFuture =
810 execution->prevExecution 812 execution->prevExecution
811 ? execution->prevExecution->result<typename detail::prevOut<In ...>::type>() 813 ? execution->prevExecution->result<typename detail::prevOut<In ...>::type>()
812 : nullptr; 814 : nullptr;
@@ -842,13 +844,13 @@ void SyncEachExecutor<PrevOut, Out, In>::run(const ExecutionPtr &execution)
842} 844}
843 845
844template<typename PrevOut, typename Out, typename In> 846template<typename PrevOut, typename Out, typename In>
845void SyncEachExecutor<PrevOut, Out, In>::run(Async::Future<Out> *out, const typename PrevOut::value_type &arg, std::false_type) 847void SyncEachExecutor<PrevOut, Out, In>::run(KAsync::Future<Out> *out, const typename PrevOut::value_type &arg, std::false_type)
846{ 848{
847 out->setValue(out->value() + SyncEachExecutor<PrevOut, Out, In>::mFunc(arg)); 849 out->setValue(out->value() + SyncEachExecutor<PrevOut, Out, In>::mFunc(arg));
848} 850}
849 851
850template<typename PrevOut, typename Out, typename In> 852template<typename PrevOut, typename Out, typename In>
851void SyncEachExecutor<PrevOut, Out, In>::run(Async::Future<Out> * /* unused */, const typename PrevOut::value_type &arg, std::true_type) 853void SyncEachExecutor<PrevOut, Out, In>::run(KAsync::Future<Out> * /* unused */, const typename PrevOut::value_type &arg, std::true_type)
852{ 854{
853 SyncEachExecutor<PrevOut, Out, In>::mFunc(arg); 855 SyncEachExecutor<PrevOut, Out, In>::mFunc(arg);
854} 856}
@@ -863,10 +865,10 @@ SyncReduceExecutor<Out, In>::SyncReduceExecutor(SyncReduceTask<Out, In> reduce,
863 865
864} // namespace Private 866} // namespace Private
865 867
866} // namespace Async 868} // namespace KAsync
867 869
868 870
869 871
870#endif // ASYNC_H 872#endif // KASYNC_H
871 873
872 874