summaryrefslogtreecommitdiffstats
path: root/async/src
diff options
context:
space:
mode:
Diffstat (limited to 'async/src')
-rw-r--r--async/src/async.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/async/src/async.h b/async/src/async.h
index 8f6457b..0d1d81e 100644
--- a/async/src/async.h
+++ b/async/src/async.h
@@ -85,6 +85,7 @@ template<typename Out, typename In>
85using SyncReduceTask = typename detail::identity<std::function<Out(In)>>::type; 85using SyncReduceTask = typename detail::identity<std::function<Out(In)>>::type;
86 86
87using ErrorHandler = std::function<void(int, const QString &)>; 87using ErrorHandler = std::function<void(int, const QString &)>;
88using Condition = std::function<bool()>;
88 89
89namespace Private 90namespace Private
90{ 91{
@@ -226,6 +227,9 @@ template<typename ReturnType, typename KJobType, ReturnType (KJobType::*KJobResu
226Job<ReturnType, Args ...> start(); 227Job<ReturnType, Args ...> start();
227#endif 228#endif
228 229
230template<typename Out>
231Job<Out> dowhile(Condition condition, ThenTask<void> func);
232
229 233
230/** 234/**
231 * A null job. 235 * A null job.
@@ -507,6 +511,31 @@ Job<ReturnType, Args ...> start()
507} 511}
508#endif 512#endif
509 513
514static void asyncWhile(const std::function<void(std::function<void(bool)>)> &body, const std::function<void()> &completionHandler) {
515 body([body, completionHandler](bool complete) {
516 if (complete) {
517 completionHandler();
518 } else {
519 asyncWhile(body, completionHandler);
520 }
521 });
522}
523 }
524template<typename Out>
525Job<Out> dowhile(Condition condition, ThenTask<void> body)
526{
527 return Async::start<void>([body, condition](Async::Future<void> &future) {
528 asyncWhile([condition, body](std::function<void(bool)> whileCallback) {
529 Async::start<void>(body).then<void>([whileCallback, condition]() {
530 whileCallback(!condition());
531 }).exec();
532 },
533 [&future]() { //while complete
534 future.setFinished();
535 });
536 });
537}
538
510template<typename Out> 539template<typename Out>
511Job<Out> null() 540Job<Out> null()
512{ 541{