summaryrefslogtreecommitdiffstats
path: root/async/src/async.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-01 10:59:36 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-01 10:59:36 +0200
commitf407e12321dada7470e561cefd576031cd9e4168 (patch)
treec27aa2f26ae6110d9b46c015a963697c1a7b530c /async/src/async.h
parent08e35aad0b53364fb82e830f1b2e2ceb60658ea5 (diff)
downloadsink-f407e12321dada7470e561cefd576031cd9e4168.tar.gz
sink-f407e12321dada7470e561cefd576031cd9e4168.zip
dowhile cleanup, second dowhile version without separate condition.
Diffstat (limited to 'async/src/async.h')
-rw-r--r--async/src/async.h40
1 files changed, 13 insertions, 27 deletions
diff --git a/async/src/async.h b/async/src/async.h
index 0d1d81e..57879a7 100644
--- a/async/src/async.h
+++ b/async/src/async.h
@@ -227,8 +227,19 @@ template<typename ReturnType, typename KJobType, ReturnType (KJobType::*KJobResu
227Job<ReturnType, Args ...> start(); 227Job<ReturnType, Args ...> start();
228#endif 228#endif
229 229
230template<typename Out> 230/**
231Job<Out> dowhile(Condition condition, ThenTask<void> func); 231 * Async while loop.
232 *
233 * The loop continues while @param condition returns true.
234 */
235Job<void> dowhile(Condition condition, ThenTask<void> func);
236
237/**
238 * Async while loop.
239 *
240 * Loop continues while body returns true.
241 */
242Job<void> dowhile(ThenTask<bool> body);
232 243
233 244
234/** 245/**
@@ -249,7 +260,6 @@ Job<Out> null();
249template<typename Out> 260template<typename Out>
250Job<Out> error(int errorCode = 1, const QString &errorMessage = QString()); 261Job<Out> error(int errorCode = 1, const QString &errorMessage = QString());
251 262
252
253class JobBase 263class JobBase
254{ 264{
255 template<typename Out, typename ... In> 265 template<typename Out, typename ... In>
@@ -511,30 +521,6 @@ Job<ReturnType, Args ...> start()
511} 521}
512#endif 522#endif
513 523
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 524
539template<typename Out> 525template<typename Out>
540Job<Out> null() 526Job<Out> null()