Commit Graph

9 Commits

Author SHA1 Message Date
Simon Brunel
5e754d1b08 Minor code style cleanup 2017-06-10 10:06:25 +02:00
Simon Brunel
da3ae12c02 More QPromise<T/void> unit tests 2017-06-10 09:58:22 +02:00
Simon Brunel
81625e1964 Add multithreading support
Make QPromise thread safe but also ensure that continuation lambdas (then/fail/finally) are called in the thread of the promise instance they are attached to.
2017-06-04 22:22:26 +02:00
Simon Brunel
9bbef41a50 C++11 optimizations and (basic) benchmark
Make continuation methods const (then/fail/finally) and ensure that the resolved promise value/error is copied only when required, same for user lambdas (dispatching result is now fully handled by the PromiseData).
2017-06-03 10:04:28 +02:00
Simon Brunel
a8ad3619b9 Setup Travis CI builds and code coverage
Built with Qt 5.4.2/GCC 4.8.4, code coverage with LCOV 1.13 and reported to Codecov.
2017-05-26 14:39:11 +02:00
Simon Brunel
4919a68959 Enhance QFuture integration and add unit tests
QFuture canceled with `QFuture::cancel()` now rejects attached promises with `QPromiseCanceledException`. In case the future is canceled because an exception (e) has been thrown, the promise is rejected with the same (e) exception (or `QUnhandledException` if not a subclass of `QException`).
2017-05-25 18:00:17 +02:00
Simon Brunel
596855f579 Move helpers in separate file and add unit tests
Gather helpers in `promisehelpers.h` and add a global include file to make easier integration with the lib (`#include <QtPromise>`).
2017-05-25 09:19:36 +02:00
Simon Brunel
ce3ed72dd4 Promise creation from callback only (resolver)
Make sure that the promise state can only be changed by the promise producer (and not consumers) by removing the `fulfill` and `reject` methods from the instance members and introducing a new constructor accepting a resolver lambda. That also means that a promise can't anymore be default constructed.

Add the static `QPromise<T>::resolve` and `QPromise<T>::reject` methods to create synchronously fulfilled or rejected promises, and fix the `qPromise` helper to handle deduced promises (e.g. `qPromise(QFuture<int>()) -> QPromise<int>`).
2017-05-20 09:40:42 +02:00
Simon Brunel
6a642446df Initial implementation 2017-05-14 19:03:01 +02:00