diff options
Diffstat (limited to 'async/src')
-rw-r--r-- | async/src/async.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/async/src/async.h b/async/src/async.h index e4b06a9..a528571 100644 --- a/async/src/async.h +++ b/async/src/async.h | |||
@@ -31,6 +31,11 @@ | |||
31 | #include <QObject> | 31 | #include <QObject> |
32 | 32 | ||
33 | 33 | ||
34 | /* | ||
35 | * TODO: on .then and potentially others: support for ThenTask without future argument and return value which makes it implicitly a sync continuation. Useful for typical value consumer continuations. | ||
36 | * TODO: error continuation on .then and others. | ||
37 | * TODO: instead of passing the future objects callbacks could be provided for result reporting (we can still use the future object internally | ||
38 | */ | ||
34 | namespace Async { | 39 | namespace Async { |
35 | 40 | ||
36 | template<typename PrevOut, typename Out, typename ... In> | 41 | template<typename PrevOut, typename Out, typename ... In> |
@@ -157,6 +162,18 @@ Job<Out> null() | |||
157 | return Async::start<Out>([](Async::Future<Out> &future) {future.setFinished();}); | 162 | return Async::start<Out>([](Async::Future<Out> &future) {future.setFinished();}); |
158 | } | 163 | } |
159 | 164 | ||
165 | /** | ||
166 | * An error job. | ||
167 | * | ||
168 | * An async error. | ||
169 | * | ||
170 | */ | ||
171 | template<typename Out> | ||
172 | Job<Out> error(int errorCode = 1, const QString &errorMessage = QString()) | ||
173 | { | ||
174 | return Async::start<Out>([errorCode, errorMessage](Async::Future<Out> &future) {future.setError(errorCode, errorMessage);}); | ||
175 | } | ||
176 | |||
160 | class JobBase | 177 | class JobBase |
161 | { | 178 | { |
162 | template<typename Out, typename ... In> | 179 | template<typename Out, typename ... In> |
@@ -225,6 +242,8 @@ public: | |||
225 | template<typename OutOther, typename ... InOther> | 242 | template<typename OutOther, typename ... InOther> |
226 | Job<OutOther, InOther ...> then(ThenTask<OutOther, InOther ...> func, ErrorHandler errorFunc = ErrorHandler()) | 243 | Job<OutOther, InOther ...> then(ThenTask<OutOther, InOther ...> func, ErrorHandler errorFunc = ErrorHandler()) |
227 | { | 244 | { |
245 | //FIXME are we leaking the executor? | ||
246 | //The executor is copied with ever job instance, so use a sharedpointer? | ||
228 | return Job<OutOther, InOther ...>(new Private::ThenExecutor<OutOther, InOther ...>(func, errorFunc, mExecutor)); | 247 | return Job<OutOther, InOther ...>(new Private::ThenExecutor<OutOther, InOther ...>(func, errorFunc, mExecutor)); |
229 | } | 248 | } |
230 | 249 | ||
@@ -275,6 +294,7 @@ namespace Async { | |||
275 | template<typename Out> | 294 | template<typename Out> |
276 | Job<Out> start(ThenTask<Out> func) | 295 | Job<Out> start(ThenTask<Out> func) |
277 | { | 296 | { |
297 | //FIXME we're leaking the exucutor, use a shared pointer | ||
278 | return Job<Out>(new Private::ThenExecutor<Out>(func)); | 298 | return Job<Out>(new Private::ThenExecutor<Out>(func)); |
279 | } | 299 | } |
280 | 300 | ||
@@ -287,7 +307,7 @@ Future<PrevOut>* Executor<PrevOut, Out, In ...>::chainup() | |||
287 | mPrev->exec(); | 307 | mPrev->exec(); |
288 | return static_cast<Async::Future<PrevOut>*>(mPrev->result()); | 308 | return static_cast<Async::Future<PrevOut>*>(mPrev->result()); |
289 | } else { | 309 | } else { |
290 | return 0; | 310 | return nullptr; |
291 | } | 311 | } |
292 | } | 312 | } |
293 | 313 | ||