summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-28 09:46:28 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-28 09:46:28 +0200
commitde00fa24da6f5af70a8a8f95ab6d4f996ffeb6bb (patch)
treecd6e09dadb7d9849b071355f408686f8a33df1ba
parent3012dc36bbc40e6f8c07a6af7b2fba9d6c826399 (diff)
downloadsink-de00fa24da6f5af70a8a8f95ab6d4f996ffeb6bb.tar.gz
sink-de00fa24da6f5af70a8a8f95ab6d4f996ffeb6bb.zip
Async::wait
Useful in i.e. loops that have to wait a bit before every execution.
-rw-r--r--async/src/async.cpp13
-rw-r--r--async/src/async.h5
2 files changed, 18 insertions, 0 deletions
diff --git a/async/src/async.cpp b/async/src/async.cpp
index e92d333..0e86a84 100644
--- a/async/src/async.cpp
+++ b/async/src/async.cpp
@@ -20,6 +20,7 @@
20#include <QCoreApplication> 20#include <QCoreApplication>
21#include <QDebug> 21#include <QDebug>
22#include <QEventLoop> 22#include <QEventLoop>
23#include <QTimer>
23 24
24using namespace Async; 25using namespace Async;
25 26
@@ -133,3 +134,15 @@ Job<void> Async::dowhile(ThenTask<bool> body)
133 }); 134 });
134} 135}
135 136
137Job<void> Async::wait(int delay)
138{
139 auto timer = QSharedPointer<QTimer>::create();
140 return Async::start<void>([timer, delay](Async::Future<void> &future) {
141 timer->setSingleShot(true);
142 QObject::connect(timer.data(), &QTimer::timeout, [&future]() {
143 future.setFinished();
144 });
145 timer->start(delay);
146 });
147}
148
diff --git a/async/src/async.h b/async/src/async.h
index 18b5979..b1f1121 100644
--- a/async/src/async.h
+++ b/async/src/async.h
@@ -285,6 +285,11 @@ template<typename Out>
285Job<Out> iterate(const Out &container); 285Job<Out> iterate(const Out &container);
286 286
287/** 287/**
288 * Async delay.
289 */
290Job<void> wait(int delay);
291
292/**
288 * A null job. 293 * A null job.
289 * 294 *
290 * An async noop. 295 * An async noop.