From c4fc276f4af964ce586e009ea3d0c728bb660331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Sun, 5 Apr 2015 01:05:55 +0200 Subject: 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. --- async/src/async.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'async/src/async.cpp') 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 @@ using namespace Async; +Private::Execution::Execution(const Private::ExecutorBasePtr &executor) + : executor(executor) + , resultBase(nullptr) + , isRunning(false) + , isFinished(false) +{ +} + +Private::Execution::~Execution() +{ + if (resultBase) { + resultBase->releaseExecution(); + delete resultBase; + } + prevExecution.reset(); +} + +void Private::Execution::setFinished() +{ + isFinished = true; + //executor.clear(); +} + +void Private::Execution::releaseFuture() +{ + resultBase = 0; +} + +bool Private::Execution::errorWasHandled() const +{ + Execution * const exec = this; + while (exec) { + if (exec->executor->hasErrorFunc()) { + return true; + } + exec = exec->prevExecution.data(); + } + return false; +} + + + + + Private::ExecutorBase::ExecutorBase(const ExecutorBasePtr &parent) : mPrev(parent) { @@ -34,6 +78,8 @@ Private::ExecutorBase::~ExecutorBase() } + + JobBase::JobBase(const Private::ExecutorBasePtr &executor) : mExecutor(executor) { -- cgit v1.2.3