summaryrefslogtreecommitdiffstats
path: root/async/autotests/testkjob.cpp
diff options
context:
space:
mode:
authorDan Vrátil <dvratil@redhat.com>2015-03-30 17:49:26 +0200
committerDan Vrátil <dvratil@redhat.com>2015-03-30 17:49:28 +0200
commit8f2fed8d2a1b23a8f318047b6592ad64b6ecbd22 (patch)
tree6f8d5ea2dc8695dfc6c3c641c2ef044ad5810bd8 /async/autotests/testkjob.cpp
parent1d946c166cc7a4a2556e8bfaab7dc66695b555e1 (diff)
downloadsink-8f2fed8d2a1b23a8f318047b6592ad64b6ecbd22.tar.gz
sink-8f2fed8d2a1b23a8f318047b6592ad64b6ecbd22.zip
Async: initial support for native chaining of KJobs
It is now possible use KJob-derived jobs with libasync without having to write lambda wrappers. auto job = Async::start<ReturnType, MyKJob, MyKJob::result, Args ...) .then<ReturnType, OtherKJob, OtherKJob::result, PrevKJobReturnType>(); job.exec(arg1, arg2, ...); The reason for this approach (instead of taking KJob* as an argument is that we usually want the KJob ctor arguments to depend on result of previous job. At least in case of Async::start() however it makes sense to support passing KJob* as an argument (not yet implemented). In future we should also support custom error handlers. The KJob integration is build-time optional, but enabled by default (pass -DWITH_KJOB=FALSE to CMake to disable). Adds KCoreAddons dependency.
Diffstat (limited to 'async/autotests/testkjob.cpp')
-rw-r--r--async/autotests/testkjob.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/async/autotests/testkjob.cpp b/async/autotests/testkjob.cpp
new file mode 100644
index 0000000..b86f913
--- /dev/null
+++ b/async/autotests/testkjob.cpp
@@ -0,0 +1,28 @@
1#include "testkjob.h"
2
3TestKJob::TestKJob(int result)
4 : mResult(result)
5{
6 connect(&mTimer, &QTimer::timeout,
7 this, &TestKJob::onTimeout);
8 mTimer.setSingleShot(true);
9 mTimer.setInterval(200);
10}
11
12TestKJob::~TestKJob()
13{}
14
15void TestKJob::start()
16{
17 mTimer.start();
18}
19
20int TestKJob::result()
21{
22 return mResult;
23}
24
25void TestKJob::onTimeout()
26{
27 emitResult();
28} \ No newline at end of file