diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 6ac38b1..a6c1e31 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -38,7 +38,6 @@ module.exports = { 'qtpromise/qpromise/then', 'qtpromise/qpromise/timeout', 'qtpromise/qpromise/wait', - 'qtpromise/qpromise/all.md', 'qtpromise/qpromise/reject.md', 'qtpromise/qpromise/resolve.md' ] @@ -46,13 +45,13 @@ module.exports = { { title: 'Helpers', children: [ + 'qtpromise/helpers/all', 'qtpromise/helpers/attempt', 'qtpromise/helpers/connect', 'qtpromise/helpers/each', 'qtpromise/helpers/filter', 'qtpromise/helpers/map', - 'qtpromise/helpers/resolve', - 'qtpromise/helpers/qpromiseall' + 'qtpromise/helpers/resolve' ] }, { diff --git a/docs/qtpromise/api-reference.md b/docs/qtpromise/api-reference.md index 344eda5..62693ef 100644 --- a/docs/qtpromise/api-reference.md +++ b/docs/qtpromise/api-reference.md @@ -20,19 +20,18 @@ ## Static Functions -* [`[static] QPromise::all`](qpromise/all.md) * [`[static] QPromise::reject`](qpromise/reject.md) * [`[static] QPromise::resolve`](qpromise/resolve.md) ## Helpers +* [`QtPromise::all`](helpers/all.md) * [`QtPromise::attempt`](helpers/attempt.md) * [`QtPromise::connect`](helpers/connect.md) * [`QtPromise::each`](helpers/each.md) * [`QtPromise::filter`](helpers/filter.md) * [`QtPromise::map`](helpers/map.md) * [`QtPromise::resolve`](helpers/resolve.md) -* [`qPromiseAll`](helpers/qpromiseall.md) ## Exceptions @@ -42,4 +41,6 @@ ## Deprecations +* `[static] QPromise::all`: use [`QtPromise::all`](helpers/all.md) instead (since 0.5.0) * `QtPromise::qPromise`: use [`QtPromise::resolve`](helpers/resolve.md) instead (since 0.5.0) +* `QtPromise::qPromiseAll`: use [`QtPromise::all`](helpers/all.md) instead (since 0.5.0) diff --git a/docs/qtpromise/helpers/all.md b/docs/qtpromise/helpers/all.md new file mode 100644 index 0000000..4928f6c --- /dev/null +++ b/docs/qtpromise/helpers/all.md @@ -0,0 +1,33 @@ +--- +title: all +--- + +# QtPromise::all + +*Since: 0.5.0* + +``` +QtPromise::all(Sequence> promises) -> QPromise> +QtPromise::all(Sequence> promises) -> QPromise +``` + +Returns a `QPromise>` (or `QPromise`) that fulfills when **all** `promises` of (the same) type `T` have been fulfilled. The `output` value is a vector containing all the values of `promises`, in the same order, i.e., at the respective positions to the original sequence, regardless of completion order. + +If any of the given `promises` fail, `output` immediately rejects with the error of the promise that rejected, whether or not the other promises are resolved. + +`Sequence` is any STL compatible container (eg. `QVector`, `QList`, `std::vector`, etc.) + +```cpp +QVector > promises{ + download(QUrl("http://a...")), + download(QUrl("http://b...")), + download(QUrl("http://c...")) +}; + +auto output = QtPromise::all(promises); + +// output type: QPromise> +output.then([](const QVector& res) { + // {...} +}); +``` diff --git a/docs/qtpromise/helpers/qpromiseall.md b/docs/qtpromise/helpers/qpromiseall.md deleted file mode 100644 index 5036ae7..0000000 --- a/docs/qtpromise/helpers/qpromiseall.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: qPromiseAll ---- - -# qPromiseAll - -*Since: 0.1.0* - -``` -qPromiseAll(Sequence> promises) -> QPromise> -qPromiseAll(Sequence> promises) -> QPromise -``` - -This method simply calls the appropriated [`QPromise::all`](../qpromise/all.md) static method based on the given `QVector` type. In some cases, this method is more convenient than the static one since it avoid some extra typing: - -```cpp -QVector > promises{...} - -auto output = qPromiseAll(promises); -// eq. QPromise::all(promises) -``` - diff --git a/docs/qtpromise/qpromise/all.md b/docs/qtpromise/qpromise/all.md index ac27503..63b58de 100644 --- a/docs/qtpromise/qpromise/all.md +++ b/docs/qtpromise/qpromise/all.md @@ -31,4 +31,4 @@ output.then([](const QVector& res) { }); ``` -See also: [`qPromiseAll`](../helpers/qpromiseall.md) +See also: [`QtPromise::all`](../helpers/all.md) diff --git a/src/qtpromise/qpromise.h b/src/qtpromise/qpromise.h index 3da218b..d105b42 100644 --- a/src/qtpromise/qpromise.h +++ b/src/qtpromise/qpromise.h @@ -98,8 +98,11 @@ public: map(Functor fn); public: // STATIC + + // DEPRECATED (remove at version 1) template