Commit Graph

84 Commits

Author SHA1 Message Date
Dmitriy Purgin
0c3955cca5
Implement QPromise<T>::convert<U>() (#41)
Converts the resolved value of `QPromise<T>` to the type `U`. Depending on types `T` and `U`, it performs a static cast, calls a converting constructor or tries to convert using `QVariant`.
2020-11-22 17:26:06 +01:00
Sören Sprößig
60b36e7a70
Fix Clang/GCC warnings and update compile options (#39) 2020-10-26 21:51:52 +01:00
Simon Brunel
f7639e921e Bump version to 0.6.0 2020-10-01 23:00:38 +02:00
Simon Brunel
1752255e7b Upgrade npm dependencies for security fixes 2020-10-01 22:54:58 +02:00
Simon Brunel
13b4bb65d2 Fix CMake FetchContent documentation GIT_TAG 2020-10-01 22:48:20 +02:00
Peter Würtz
b7ecd95b04
Fix deprecations and compile warnings (#34)
- Use std::invoke_result, fallback to std::result_of on C++11/14.
- Use RVO instead of std::move (GCC warning: redundant-move).
- Replace QSharedPointer with std::shared_ptr (GCC warning: unititialized value).
- QLinkedList is deprecated in Qt 5.15.
2020-04-02 13:39:03 +02:00
Simon Brunel
88289a7635 Fix npm security warning (docs only) 2020-03-22 17:50:16 +01:00
Simon Brunel
6deec9f51f Fix support for auto args in constructor callbacks
Broken since 78417b5, this bug creates an infinite recursion at runtime while trying to resolve the QPromise<T> template constructor if the given callback is either an invalid function or a valid callback but using auto args (C++14).

Related warning: C4717: recursive on all control paths, function will cause runtime stack overflow.
2020-03-22 17:50:16 +01:00
Simon Brunel
d43657fbd5 Use clang-format for code style consistency
Based on the WebKit preset and following 'most' of the Qt guidelines, except a few rules that work better for promise continuation lambdas. Requires clang-format 11.
2020-03-22 17:50:16 +01:00
Dmitriy Purgin
b99e468c84
More verbose description of throwing an exception from a QtConcurrent thread (#31) 2020-02-18 22:31:41 +01:00
Simon Brunel
be5455a8c8 Use C++11 curly braces initialization 2020-02-17 20:02:26 +01:00
Simon Brunel
0bfdddd887 Use QSharedPointer::create and std::make_shared 2020-02-16 11:42:57 +01:00
Simon Brunel
2c1e631aed Include Qt classes by module and remove unnecessary comments 2020-02-11 22:25:08 +01:00
Simon Brunel
d5a82518f9 Simplify tests directory structure 2020-02-11 22:13:57 +01:00
Dmitriy Purgin
1ad99391a3
std::chrono overloads for .timeout() and .delay() (#30)
Add convenience overloads accepting durations from the C++ Standard Library.
2020-02-11 22:07:05 +01:00
Simon Brunel
78417b5813 Fix support for std::function as continuation handler 2020-02-06 22:52:07 +01:00
Simon Brunel
58738a5604 Simplify license notice in source files 2020-02-06 22:33:19 +01:00
Simon Brunel
7ee51de987
Fix Google Analytics plugin docs config 2020-01-24 04:58:32 +01:00
Simon Brunel
6639ea52db Migrate to CMake to build the entire project 2020-01-12 21:04:43 +01:00
Simon Brunel
7f9013a878 Add CMake support and enhance the getting started docs
- Add a root CMakeLists.txt defining an INTERFACE target.
- Add CMake, qpm, Git and download installation instructions.
- Add CMake and qmake integration instructions.
- Remove smooth scroll when navigating the docs.
- Add links validation to `npm run docs:link`.
- Reorganize the sidebar API Reference section.
2020-01-09 20:45:04 +01:00
Simon Brunel
cc29ef3512 Fix docs C++ snippet for the .fail() args
- Fix the wrong lambda format (missing `[]`).
- Make consistent argument naming (`error`).
- Use `const &` when appropriated.
2020-01-04 13:25:19 +01:00
Simon Brunel
3c1461b8d0 Enhance the documentation and add markdown lint
- Add npm package.json to make easier maintaining dependencies.
- Make markdown files consistent using remark.
- Wrap markdown lines to 100 characters.
- Better README.md layout and visual.
- Enable VuePress landing/home page.
- Upgrade to latest VuePress version.
- Add link to the new Qt Marketplace.
2019-12-21 10:27:26 +01:00
Simon Brunel
815dc443b9 Add MIT license header to all source files 2019-12-20 21:42:19 +01:00
Simon Brunel
67837827b1 Bump version to 0.5.0 2019-03-31 22:14:45 +02:00
Simon Brunel
e3f0f054af Implement QPromise<Sequence<T>>::reduce(reducer, initialValue)
Iterates over all the promise values (i.e. `Sequence<T>`) and reduces the sequence to a single value using the given `reducer` function and an optional `initialValue`. Also provide a static helper to directly reduce values (`QtPromise::reduce(values, reducer, initialValue)`).
2019-03-31 15:16:08 +02:00
Simon Brunel
cbf4cc7867 Rename qPromiseAll() helper to QtPromise::all()
For consistency with other helpers, deprecate `qPromiseAll()` in favor of `QtPromise::all()`.
2019-03-25 14:45:51 +01:00
Simon Brunel
963ec621e1 Rename qPromise() helper to QtPromise::resolve()
For consistency with other helpers, deprecate `qPromise()` in favor of `QtPromise::resolve()` but also add support for calling this helper with lvalue. Add extra unit tests to make sure that rvalue is not copied.
2019-03-25 14:45:41 +01:00
Simon Brunel
1f30224578 Add support for creating promises from Qt signals (#25)
Introduce a new `QtPromise::connect()` helper that allows to create a promise resolved from a single signal and optionally, rejected by another one (from a different object or not). The promise type is determined by the type of the first signal argument (other arguments are currently ignored). A `QPromise<void>` is returned if the resolve signal doesn't provide any argument.

If the rejection is emitted before the promise is resolved, the promise will be rejected with the value of the first argument (other arguments being ignored). If the rejection signal doesn't provide any argument, the promise will be rejected with `QPromiseUndefinedException` if the signal is emitted. Additionally, the promise will be automatically rejected with `QPromiseContextException` if the source object is destroyed before the promise is resolved.
2019-03-04 14:02:32 +01:00
Simon Brunel
47b90fb532 Fix Gcov warning 'version 409*, prefer version 408*' 2019-03-01 17:47:32 +01:00
Simon Brunel
63acdfaab9 Make docs formatting consistent (no explicit word wrap) 2019-03-01 17:41:32 +01:00
Simon Brunel
700098ef7b Reorganize exceptions and add unit tests 2019-03-01 17:41:32 +01:00
Simon Brunel
6110cd40d3 Test LTS and latest Qt versions in AppVeyor 2019-02-21 12:07:21 +01:00
Simon Brunel
a6d883acbd Update LICENSE year and cleanup a few comments 2019-02-18 20:30:41 +01:00
Simon Brunel
9119cc72f6 Add documentation for built-in exceptions 2019-02-01 16:06:29 +01:00
Simon Brunel
fa5a4192ff Allow undefined rejection reason
While not recommended because it makes tracking errors more difficult, it's now possible to reject a promise without explicit reason, in which case, a built-in `QPromiseUndefinedException` is thrown. This is done in anticipation of handling rejection signals without argument.
2019-01-31 19:03:57 +01:00
Simon Brunel
16229fc2c9 Integrate DocSearch (Algolia)
https://github.com/algolia/docsearch-configs/blob/master/configs/qtpromise.json
https://community.algolia.com/docsearch/
2018-09-10 12:36:31 +02:00
Simon Brunel
22faef4ac3 Bump version to 0.4.0 2018-09-09 21:27:33 +02:00
Simon Brunel
eebcb4f364 Migrate documentation to VuePress
GitBook development seems a bit stuck right now so let's switch to VuePress which, IMO, is more user friendly. Update the documentation to include the version number in which features were added and use custom container to display notes and warnings.
2018-09-09 10:55:07 +02:00
Simon Brunel
051fed5fbc Implement QPromise<Sequence<T>>::each(functor)
Call the given `functor` on each element in the promise value (i.e. `Sequence<T>`), then resolve to the original sequence unmodified. Also provide a static helper to directly filter values (`QtPromise::each(values, functor)`).
2018-09-07 16:50:29 +02:00
Simon Brunel
f610826ef0 Implement QtPromise::attempt(functor, args...)
Add a new helper that calls functor immediately and returns a promise fulfilled with the value returned by functor. Any synchronous exceptions will be turned into rejections on the returned promise. This is a convenient method that can be used instead of handling both synchronous and asynchronous exception flows.

Also simplify PromiseDispatch which now calls the functor with a variable number of arguments (including none).
2018-05-31 09:02:51 +02:00
Simon Brunel
4fa7a37750 Implement QPromise<Sequence<T>>::filter(filterer)
Add a new method that iterates over all the promise values (i.e. `Sequence<T>`) and filters the sequence to another using the given `filterer` function. If `filterer` returns `true`, a copy of the item is put in the `output` sequence, otherwise, the item will not appear in `output`. Also provide a static helper to directly filter values (`QtPromise::filter(values, filterer)`).
2018-05-30 18:52:53 +02:00
Simon Brunel
69c07855f4
Implement QPromise<Sequence<T>>::map(mapper) (#15)
Iterate over all the promise value (i.e. `Sequence<T>`) and map the sequence to another using the given `mapper` function. Also provide a static helper to directly map values (`QtPromise::map(values, mapper)`).
2018-05-26 11:40:51 +02:00
Simon Brunel
4cfe2e54f4 Move resolver related classes in a separate file. 2018-05-23 21:24:14 +02:00
Simon Brunel
54d88f16a3 Reorganize helpers unit tests 2018-05-23 21:24:00 +02:00
Peter Würtz
bdf3619469 Add AppVeyor configuration file for running MSVC tests (#19)
Qt 5.6/msvc2013 and Qt 5.9/msvc2013_64
2018-05-23 18:31:35 +02:00
Peter Würtz
8da467e9da Relax timing constraints when checking timeout in tst_timeout 2018-05-21 10:12:35 +02:00
Peter Würtz
efb6001b9d Upgrade TravisCI environment to Qt 5.6 and GCC 4.9 2018-05-18 11:32:01 +02:00
Simon Brunel
26a2110a14 Fix GCC -Wold-style-cast warnings
Explicitly enable -Wold-style-cast and make all warnings into errors in tests (-Werror on GCC, -WX on MSVC).
2018-05-10 11:51:17 +02:00
Simon Brunel
fa987a5044 Cleanup promise captured in resolve/reject
Make sure that QPromiseResolve and QPromiseReject release their associated promise as soon as one of them is resolved or rejected, ensuring that the promise data is cleaned up once resolved (that fixes cases where one or both of them are captured in a signal/slot connection lambda)
2018-05-10 11:51:17 +02:00
Simon Brunel
7b0cba5b9d Allow QSharedPointer as rejection reason
Embed the promise fulfillment value and rejection reason in respectively PromiseValue and PromiseError private wrappers, both storing the data in a shared pointer (QPromiseError is now deprecated).
2018-05-10 11:51:14 +02:00