summaryrefslogtreecommitdiffstats
path: root/async/src/async.cpp
diff options
context:
space:
mode:
authorDan Vrátil <dvratil@redhat.com>2015-04-05 01:05:55 +0200
committerDan Vrátil <dvratil@redhat.com>2015-04-06 18:57:48 +0200
commitc4fc276f4af964ce586e009ea3d0c728bb660331 (patch)
treef592de8a592cbe538953482c34f319e8b4adbd86 /async/src/async.cpp
parent1cb20215e384712ccbc98f3ecc4711451730c696 (diff)
downloadsink-c4fc276f4af964ce586e009ea3d0c728bb660331.tar.gz
sink-c4fc276f4af964ce586e009ea3d0c728bb660331.zip
Async: improve error handling and error propagation
The error is now propagated to the top-most (user-owned) Future. When an error occurs, no further tasks are executed. The first error handler function in the chain is also called, if there's any.
Diffstat (limited to 'async/src/async.cpp')
-rw-r--r--async/src/async.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/async/src/async.cpp b/async/src/async.cpp
index 5e26bd8..c780878 100644
--- a/async/src/async.cpp
+++ b/async/src/async.cpp
@@ -24,6 +24,50 @@
24 24
25using namespace Async; 25using namespace Async;
26 26
27Private::Execution::Execution(const Private::ExecutorBasePtr &executor)
28 : executor(executor)
29 , resultBase(nullptr)
30 , isRunning(false)
31 , isFinished(false)
32{
33}
34
35Private::Execution::~Execution()
36{
37 if (resultBase) {
38 resultBase->releaseExecution();
39 delete resultBase;
40 }
41 prevExecution.reset();
42}
43
44void Private::Execution::setFinished()
45{
46 isFinished = true;
47 //executor.clear();
48}
49
50void Private::Execution::releaseFuture()
51{
52 resultBase = 0;
53}
54
55bool Private::Execution::errorWasHandled() const
56{
57 Execution * const exec = this;
58 while (exec) {
59 if (exec->executor->hasErrorFunc()) {
60 return true;
61 }
62 exec = exec->prevExecution.data();
63 }
64 return false;
65}
66
67
68
69
70
27Private::ExecutorBase::ExecutorBase(const ExecutorBasePtr &parent) 71Private::ExecutorBase::ExecutorBase(const ExecutorBasePtr &parent)
28 : mPrev(parent) 72 : mPrev(parent)
29{ 73{
@@ -34,6 +78,8 @@ Private::ExecutorBase::~ExecutorBase()
34} 78}
35 79
36 80
81
82
37JobBase::JobBase(const Private::ExecutorBasePtr &executor) 83JobBase::JobBase(const Private::ExecutorBasePtr &executor)
38 : mExecutor(executor) 84 : mExecutor(executor)
39{ 85{