diff --git a/README.md b/README.md index 51439a6..90b6b6e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ Promises/A+ # QtPromise + [![qpm](https://img.shields.io/github/release/simonbrunel/qtpromise.svg?style=flat-square&label=qpm&colorB=4CAF50)](https://www.qpm.io/packages/com.github.simonbrunel.qtpromise/index.html) [![Travis](https://img.shields.io/travis/simonbrunel/qtpromise/master.svg?style=flat-square)](https://travis-ci.org/simonbrunel/qtpromise) [![coverage](https://img.shields.io/codecov/c/github/simonbrunel/qtpromise.svg?style=flat-square)](https://codecov.io/gh/simonbrunel/qtpromise) [Promises/A+](https://promisesaplus.com/) implementation for [Qt/C++](https://www.qt.io/). @@ -9,10 +10,11 @@ Requires [Qt 5.6](https://www.qt.io/download/) (or later) with [C++11 support en ## Documentation -* [Getting Started](https://qtpromise.netlify.com/qtpromise/getting-started) -* [Thread-Safety](https://qtpromise.netlify.com/qtpromise/thread-safety) -* [QtConcurrent](https://qtpromise.netlify.com/qtpromise/qtconcurrent) -* [API Reference](https://qtpromise.netlify.com/qtpromise/api-reference) +* [Getting Started](https://qtpromise.netlify.com/qtpromise/getting-started.html) +* [QtConcurrent](https://qtpromise.netlify.com/qtpromise/qtconcurrent.html) +* [Thread-Safety](https://qtpromise.netlify.com/qtpromise/thread-safety.html) +* [API Reference](https://qtpromise.netlify.com/qtpromise/api-reference.html) ## License + QtPromise is available under the [MIT license](LICENSE). diff --git a/book.json b/book.json deleted file mode 100644 index 6687058..0000000 --- a/book.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "title": "QtPromise", - "description": "Promises/A+ implementation for Qt/C++", - "author": "Simon Brunel", - "gitbook": "3.2.3", - "root": "docs", - "plugins": [ - "-lunr", - "-search", - "search-plus", - "anchorjs", - "edit-link", - "expand-active-chapter", - "ga", - "github" - ], - "pluginsConfig": { - "anchorjs": { - "icon": "#", - "placement": "left", - "visible": "always" - }, - "edit-link": { - "base": "https://github.com/simonbrunel/qtpromise/edit/master/docs" - }, - "ga": { - "token": "UA-113899811-1", - "configuration": "auto" - }, - "github": { - "url": "https://github.com/simonbrunel/qtpromise" - }, - "theme-default": { - "showLevel": false, - "styles": { - "website": "assets/style.css" - } - } - } -} diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js new file mode 100644 index 0000000..6afd0ce --- /dev/null +++ b/docs/.vuepress/config.js @@ -0,0 +1,54 @@ +module.exports = { + title: 'QtPromise', + description: 'Promises/A+ implementation for Qt/C++', + ga: 'UA-113899811-1', + head: [ + ['link', { rel: 'icon', href: `/favicon.png` }], + ], + themeConfig: { + repo: 'simonbrunel/qtpromise', + lastUpdated: 'Last Updated', + editLinks: true, + docsDir: 'docs', + sidebar: [ + 'qtpromise/getting-started', + 'qtpromise/qtconcurrent', + 'qtpromise/thread-safety', + 'qtpromise/api-reference', + { + title: 'QPromise', + children: [ + 'qtpromise/qpromise/constructor', + 'qtpromise/qpromise/delay', + 'qtpromise/qpromise/each', + 'qtpromise/qpromise/fail', + 'qtpromise/qpromise/filter', + 'qtpromise/qpromise/finally', + 'qtpromise/qpromise/isfulfilled', + 'qtpromise/qpromise/ispending', + 'qtpromise/qpromise/isrejected', + 'qtpromise/qpromise/map', + 'qtpromise/qpromise/tap', + 'qtpromise/qpromise/tapfail', + 'qtpromise/qpromise/then', + 'qtpromise/qpromise/timeout', + 'qtpromise/qpromise/wait', + 'qtpromise/qpromise/all.md', + 'qtpromise/qpromise/reject.md', + 'qtpromise/qpromise/resolve.md' + ] + }, + { + title: 'Helpers', + children: [ + 'qtpromise/helpers/attempt', + 'qtpromise/helpers/each', + 'qtpromise/helpers/filter', + 'qtpromise/helpers/map', + 'qtpromise/helpers/qpromise', + 'qtpromise/helpers/qpromiseall' + ] + } + ] + } +} diff --git a/docs/.vuepress/override.styl b/docs/.vuepress/override.styl new file mode 100644 index 0000000..984aad2 --- /dev/null +++ b/docs/.vuepress/override.styl @@ -0,0 +1,2 @@ +$accentColor = #23b223 +$textColor = #404244 diff --git a/docs/.vuepress/public/favicon.ico b/docs/.vuepress/public/favicon.ico new file mode 100644 index 0000000..50cb9fd Binary files /dev/null and b/docs/.vuepress/public/favicon.ico differ diff --git a/docs/.vuepress/public/favicon.png b/docs/.vuepress/public/favicon.png new file mode 100644 index 0000000..31c7d07 Binary files /dev/null and b/docs/.vuepress/public/favicon.png differ diff --git a/docs/.vuepress/style.styl b/docs/.vuepress/style.styl new file mode 100644 index 0000000..8583e44 --- /dev/null +++ b/docs/.vuepress/style.styl @@ -0,0 +1,4 @@ +@import 'override.styl' + +.content a code + color: $accentColor diff --git a/docs/README.md b/docs/README.md index a41087f..38ffc2a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,11 +5,5 @@ Requires [Qt 5.6](https://www.qt.io/download/) (or later) with [C++11 support enabled](https://wiki.qt.io/How_to_use_C++11_in_your_Qt_Projects). -## QtPromise for C++ -* [Getting Started](qtpromise/getting-started.md) -* [Thread-Safety](qtpromise/thread-safety.md) -* [QtConcurrent](qtpromise/qtconcurrent.md) -* [API Reference](qtpromise/api-reference.md) - ## License QtPromise is available under the [MIT license](https://github.com/simonbrunel/qtpromise/blob/master/LICENSE). diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md deleted file mode 100644 index a2b88ba..0000000 --- a/docs/SUMMARY.md +++ /dev/null @@ -1,29 +0,0 @@ -### QtPromise for C++ -* [Getting Started](qtpromise/getting-started.md) -* [QtConcurrent](qtpromise/qtconcurrent.md) -* [Thread-Safety](qtpromise/thread-safety.md) -* [API Reference](qtpromise/api-reference.md) - * [QPromise](qtpromise/qpromise/constructor.md) - * [.delay](qtpromise/qpromise/delay.md) - * [.each](qtpromise/qpromise/each.md) - * [.fail](qtpromise/qpromise/fail.md) - * [.filter](qtpromise/qpromise/filter.md) - * [.finally](qtpromise/qpromise/finally.md) - * [.isFulfilled](qtpromise/qpromise/isfulfilled.md) - * [.isPending](qtpromise/qpromise/ispending.md) - * [.isRejected](qtpromise/qpromise/isrejected.md) - * [.map](qtpromise/qpromise/map.md) - * [.tap](qtpromise/qpromise/tap.md) - * [.tapFail](qtpromise/qpromise/tapfail.md) - * [.then](qtpromise/qpromise/then.md) - * [.timeout](qtpromise/qpromise/timeout.md) - * [.wait](qtpromise/qpromise/wait.md) - * [::all (static)](qtpromise/qpromise/all.md) - * [::reject (static)](qtpromise/qpromise/reject.md) - * [::resolve (static)](qtpromise/qpromise/resolve.md) - * [qPromise](qtpromise/helpers/qpromise.md) - * [qPromiseAll](qtpromise/helpers/qpromiseall.md) - * [QtPromise::attempt](qtpromise/helpers/attempt.md) - * [QtPromise::each](qtpromise/helpers/each.md) - * [QtPromise::filter](qtpromise/helpers/filter.md) - * [QtPromise::map](qtpromise/helpers/map.md) diff --git a/docs/assets/style.css b/docs/assets/style.css deleted file mode 100644 index acdd3e5..0000000 --- a/docs/assets/style.css +++ /dev/null @@ -1,15 +0,0 @@ -a.anchorjs-link { - color: rgba(65, 131, 196, 0.1); - font-weight: 400; - text-decoration: none; - transition: color 100ms ease-out; - z-index: 999; -} - -a.anchorjs-link:hover { - color: rgba(65, 131, 196, 1); -} - -sup { - font-size: 0.75em !important; -} diff --git a/docs/qtpromise/api-reference.md b/docs/qtpromise/api-reference.md index b14b6c9..d4112dd 100644 --- a/docs/qtpromise/api-reference.md +++ b/docs/qtpromise/api-reference.md @@ -1,6 +1,6 @@ -## QPromise +# API Reference -### Public Members +## Functions * [`QPromise::QPromise`](qpromise/constructor.md) * [`QPromise::delay`](qpromise/delay.md) @@ -18,7 +18,7 @@ * [`QPromise::timeout`](qpromise/timeout.md) * [`QPromise::wait`](qpromise/wait.md) -### Public Static Members +## Static Functions * [`[static] QPromise::all`](qpromise/all.md) * [`[static] QPromise::reject`](qpromise/reject.md) @@ -26,9 +26,9 @@ ## Helpers -* [`qPromise`](helpers/qpromise.md) -* [`qPromiseAll`](helpers/qpromiseall.md) * [`QtPromise::attempt`](helpers/attempt.md) * [`QtPromise::each`](helpers/each.md) * [`QtPromise::filter`](helpers/filter.md) * [`QtPromise::map`](helpers/map.md) +* [`qPromise`](helpers/qpromise.md) +* [`qPromiseAll`](helpers/qpromiseall.md) diff --git a/docs/qtpromise/getting-started.md b/docs/qtpromise/getting-started.md index 36548bc..f873b3e 100644 --- a/docs/qtpromise/getting-started.md +++ b/docs/qtpromise/getting-started.md @@ -1,8 +1,10 @@ +# Getting Started + ## Installation QtPromise is a [header-only](https://en.wikipedia.org/wiki/Header-only) library, simply download the [latest release](https://github.com/simonbrunel/qtpromise/releases/latest) (or [`git submodule`](https://git-scm.com/docs/git-submodule)) and include `qtpromise.pri` from your project `.pro`. -## qpm +### qpm Alternatively and **only** if your project relies on [qpm](https://www.qpm.io/), you can install QtPromise as follow: diff --git a/docs/qtpromise/helpers/attempt.md b/docs/qtpromise/helpers/attempt.md index a2908bf..50ef77c 100644 --- a/docs/qtpromise/helpers/attempt.md +++ b/docs/qtpromise/helpers/attempt.md @@ -1,4 +1,10 @@ -## `QtPromise::attempt` +--- +title: attempt +--- + +# QtPromise::attempt + +*Since: 0.4.0* ```cpp QtPromise::attempt(Functor functor, Args...) -> QPromise diff --git a/docs/qtpromise/helpers/each.md b/docs/qtpromise/helpers/each.md index fd77d51..91e03b6 100644 --- a/docs/qtpromise/helpers/each.md +++ b/docs/qtpromise/helpers/each.md @@ -1,4 +1,10 @@ -## `QtPromise::each` +--- +title: each +--- + +# QtPromise::each + +*Since: 0.4.0* ```cpp QtPromise::each(Sequence values, Functor functor) -> QPromise> @@ -8,10 +14,10 @@ QtPromise::each(Sequence values, Functor functor) -> QPromise> // - Functor: Function(T value, int index) -> void | QPromise ``` -Calls the given `functor` on each element in `values` then resolves to the original sequence -unmodified. If `functor` throws, `output` is rejected with the new exception. +Calls the given `functor` on each element in `values` then resolves to the original sequence +unmodified. If `functor` throws, `output` is rejected with the new exception. -If `functor` returns a promise (or `QFuture`), the `output` promise is delayed until all the +If `functor` returns a promise (or `QFuture`), the `output` promise is delayed until all the promises are resolved. If any of the promises fail, `output` immediately rejects with the error of the promise that rejected, whether or not the other promises are resolved. diff --git a/docs/qtpromise/helpers/filter.md b/docs/qtpromise/helpers/filter.md index 257d280..5628ea6 100644 --- a/docs/qtpromise/helpers/filter.md +++ b/docs/qtpromise/helpers/filter.md @@ -1,4 +1,10 @@ -## `QtPromise::filter` +--- +title: filter +--- + +# QtPromise::filter + +*Since: 0.4.0* ```cpp QtPromise::filter(Sequence values, Filterer filterer) -> QPromise> @@ -38,7 +44,9 @@ output.then([](const QVector& res) { }); ``` -> **Note:** the order of the output sequence values is guarantee to be the same as the original +::: tip NOTE +The order of the output sequence values is guarantee to be the same as the original sequence, regardless of completion order of the promises returned by `filterer`. +::: See also: [`QPromise::filter`](../qpromise/filter.md) diff --git a/docs/qtpromise/helpers/map.md b/docs/qtpromise/helpers/map.md index d7ab5a1..46b2b0d 100644 --- a/docs/qtpromise/helpers/map.md +++ b/docs/qtpromise/helpers/map.md @@ -1,4 +1,10 @@ -## `QtPromise::map` +--- +title: map +--- + +# QtPromise::map + +*Since: 0.4.0* ```cpp QtPromise::map(Sequence values, Mapper mapper) -> QPromise> @@ -37,7 +43,9 @@ output.then([](const QVector& res) { }); ``` -> **Note:** the order of the output sequence values is guarantee to be the same as the original +::: tip NOTE +The order of the output sequence values is guarantee to be the same as the original sequence, regardless of completion order of the promises returned by `mapper`. +::: See also: [`QPromise::map`](../qpromise/map.md) diff --git a/docs/qtpromise/helpers/qpromise.md b/docs/qtpromise/helpers/qpromise.md index 56c3996..26ddb77 100644 --- a/docs/qtpromise/helpers/qpromise.md +++ b/docs/qtpromise/helpers/qpromise.md @@ -1,4 +1,10 @@ -## `qPromise` +--- +title: qPromise +--- + +# qPromise + +*Since: 0.1.0* ``` qPromise(T value) -> QPromise diff --git a/docs/qtpromise/helpers/qpromiseall.md b/docs/qtpromise/helpers/qpromiseall.md index 9d9741f..5036ae7 100644 --- a/docs/qtpromise/helpers/qpromiseall.md +++ b/docs/qtpromise/helpers/qpromiseall.md @@ -1,4 +1,10 @@ -## `qPromiseAll` +--- +title: qPromiseAll +--- + +# qPromiseAll + +*Since: 0.1.0* ``` qPromiseAll(Sequence> promises) -> QPromise> diff --git a/docs/qtpromise/qpromise/all.md b/docs/qtpromise/qpromise/all.md index 5ecd644..ac27503 100644 --- a/docs/qtpromise/qpromise/all.md +++ b/docs/qtpromise/qpromise/all.md @@ -1,4 +1,10 @@ -## `[static] QPromise::all` +--- +title: ::all [static] +--- + +# QPromise::all [static] + +*Since: 0.1.0* ``` [static] QPromise::all(Sequence> promises) -> QPromise> diff --git a/docs/qtpromise/qpromise/constructor.md b/docs/qtpromise/qpromise/constructor.md index 302ed20..cede2a0 100644 --- a/docs/qtpromise/qpromise/constructor.md +++ b/docs/qtpromise/qpromise/constructor.md @@ -1,6 +1,12 @@ -## `QPromise::QPromise` +--- +title: constructor +--- -``` +# QPromise::QPromise + +*Since: 0.1.0* + +```cpp QPromise::QPromise(Function resolver) ``` @@ -18,7 +24,9 @@ QPromise promise([](const QPromiseResolve& resolve, const QPromiseReje }); ``` -> **Note:** `QPromise` is specialized to not contain any value, meaning that the `resolve` callback takes no argument. +::: tip NOTE +`QPromise` is specialized to not contain any value, meaning that the `resolve` callback takes no argument. +::: **C++14** diff --git a/docs/qtpromise/qpromise/delay.md b/docs/qtpromise/qpromise/delay.md index 21af63d..1069af1 100644 --- a/docs/qtpromise/qpromise/delay.md +++ b/docs/qtpromise/qpromise/delay.md @@ -1,6 +1,12 @@ -## `QPromise::delay` +--- +title: .delay +--- -``` +# QPromise::delay + +*Since: 0.2.0* + +```cpp QPromise::delay(int msec) -> QPromise ``` diff --git a/docs/qtpromise/qpromise/each.md b/docs/qtpromise/qpromise/each.md index e7567f7..4041b91 100644 --- a/docs/qtpromise/qpromise/each.md +++ b/docs/qtpromise/qpromise/each.md @@ -1,6 +1,10 @@ -## `QPromise>::each` +--- +title: .each +--- -> **Important:** applies only to promise with sequence value. +# QPromise::each + +*Since: 0.4.0* ```cpp QPromise>::each(Functor functor) -> QPromise> @@ -10,6 +14,10 @@ QPromise>::each(Functor functor) -> QPromise> // - Functor: Function(T value, int index) -> any ``` +::: warning IMPORTANT +This method only applies to promise with sequence value. +::: + Calls the given `functor` on each element in the promise value (i.e. `Sequence`), then resolves to the original sequence unmodified. If `functor` throws, `output` is rejected with the new exception. ```cpp diff --git a/docs/qtpromise/qpromise/fail.md b/docs/qtpromise/qpromise/fail.md index 5b6d8ec..98e5a74 100644 --- a/docs/qtpromise/qpromise/fail.md +++ b/docs/qtpromise/qpromise/fail.md @@ -1,6 +1,12 @@ -## `QPromise::fail` +--- +title: .fail +--- -``` +# QPromise::fail + +*Since: 0.1.0* + +```cpp QPromise::fail(Function onRejected) -> QPromise ``` diff --git a/docs/qtpromise/qpromise/filter.md b/docs/qtpromise/qpromise/filter.md index f350b28..a8d8577 100644 --- a/docs/qtpromise/qpromise/filter.md +++ b/docs/qtpromise/qpromise/filter.md @@ -1,6 +1,10 @@ -## `QPromise>::filter` +--- +title: .filter +--- -> **Important:** applies only to promise with sequence value. +# QPromise::filter + +*Since: 0.4.0* ```cpp QPromise>::filter(Filter filterer) -> QPromise> @@ -10,6 +14,10 @@ QPromise>::filter(Filter filterer) -> QPromise> // - Filterer: Function(T value, int index) -> bool ``` +::: warning IMPORTANT +This method only applies to promise with sequence value. +::: + Iterates over all the promise values (i.e. `Sequence`) and [filters the sequence](https://en.wikipedia.org/wiki/Filter_%28higher-order_function%29) 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`. If `filterer` @@ -39,7 +47,9 @@ output.then([](const QList& res) { }); ``` -> **Note:** the order of the output sequence values is guarantee to be the same as the original +::: tip NOTE +The order of the output sequence values is guarantee to be the same as the original sequence, regardless of completion order of the promises returned by `filterer`. +::: See also: [`QtPromise::filter`](../helpers/filter.md) diff --git a/docs/qtpromise/qpromise/finally.md b/docs/qtpromise/qpromise/finally.md index 671c957..7a2e867 100644 --- a/docs/qtpromise/qpromise/finally.md +++ b/docs/qtpromise/qpromise/finally.md @@ -1,6 +1,12 @@ -## `QPromise::finally` +--- +title: .finally +--- -``` +# QPromise::finally + +*Since: 0.1.0* + +```cpp QPromise::finally(Function handler) -> QPromise ``` diff --git a/docs/qtpromise/qpromise/isfulfilled.md b/docs/qtpromise/qpromise/isfulfilled.md index 8b25e00..55a500a 100644 --- a/docs/qtpromise/qpromise/isfulfilled.md +++ b/docs/qtpromise/qpromise/isfulfilled.md @@ -1,6 +1,12 @@ -# `QPromise::isFulfilled` +--- +title: .isFulfilled +--- -``` +# QPromise::isFulfilled + +*Since: 0.1.0* + +```cpp QPromise::isFulfilled() -> bool ``` diff --git a/docs/qtpromise/qpromise/ispending.md b/docs/qtpromise/qpromise/ispending.md index 4fb5c15..4903db3 100644 --- a/docs/qtpromise/qpromise/ispending.md +++ b/docs/qtpromise/qpromise/ispending.md @@ -1,6 +1,12 @@ -# `QPromise::isPending` +--- +title: .isPending +--- -``` +# QPromise::isPending + +*Since: 0.1.0* + +```cpp QPromise::isPending() -> bool ``` diff --git a/docs/qtpromise/qpromise/isrejected.md b/docs/qtpromise/qpromise/isrejected.md index e982e51..c520058 100644 --- a/docs/qtpromise/qpromise/isrejected.md +++ b/docs/qtpromise/qpromise/isrejected.md @@ -1,6 +1,12 @@ -# `QPromise::isRejected` +--- +title: .isRejected +--- -``` +# QPromise::isRejected + +*Since: 0.1.0* + +```cpp QPromise::isRejected() -> bool ``` diff --git a/docs/qtpromise/qpromise/map.md b/docs/qtpromise/qpromise/map.md index 531dee7..35832b2 100644 --- a/docs/qtpromise/qpromise/map.md +++ b/docs/qtpromise/qpromise/map.md @@ -1,6 +1,10 @@ -## `QPromise>::map` +--- +title: .map +--- -> **Important:** applies only to promise with sequence value. +# QPromise::map + +*Since: 0.4.0* ```cpp QPromise>::map(Mapper mapper) -> QPromise> @@ -10,6 +14,10 @@ QPromise>::map(Mapper mapper) -> QPromise> // - Mapper: Function(T value, int index) -> R | QPromise ``` +::: warning IMPORTANT +This method only applies to promise with sequence value. +::: + Iterates over all the promise values (i.e. `Sequence`) and [maps the sequence](https://en.wikipedia.org/wiki/Map_%28higher-order_function%29) to another using the given `mapper` function. The type returned by `mapper` determines the type of the `output` promise. If `mapper` throws, `output` is rejected with the new exception. @@ -41,8 +49,10 @@ output.then([](const QVector& res) { }); ``` -> **Note:** the order of the output sequence values is guarantee to be the same as the original +::: tip NOTE +The order of the output sequence values is guarantee to be the same as the original sequence, regardless of completion order of the promises returned by `mapper`. +::: This function is provided for convenience and is similar to: diff --git a/docs/qtpromise/qpromise/reject.md b/docs/qtpromise/qpromise/reject.md index 3eb0e8f..93a57a3 100644 --- a/docs/qtpromise/qpromise/reject.md +++ b/docs/qtpromise/qpromise/reject.md @@ -1,6 +1,12 @@ -## `[static] QPromise::reject` +--- +title: ::reject [static] +--- -``` +# QPromise::reject [static] + +*Since: 0.1.0* + +```cpp [static] QPromise::reject(any reason) -> QPromise ``` diff --git a/docs/qtpromise/qpromise/resolve.md b/docs/qtpromise/qpromise/resolve.md index 3d49f7f..1ca85ef 100644 --- a/docs/qtpromise/qpromise/resolve.md +++ b/docs/qtpromise/qpromise/resolve.md @@ -1,4 +1,10 @@ -## `[static] QPromise::resolve` +--- +title: ::resolve [static] +--- + +# QPromise::resolve [static] + +*Since: 0.1.0* ``` [static] QPromise::resolve(T value) -> QPromise diff --git a/docs/qtpromise/qpromise/tap.md b/docs/qtpromise/qpromise/tap.md index fe93620..08e2f07 100644 --- a/docs/qtpromise/qpromise/tap.md +++ b/docs/qtpromise/qpromise/tap.md @@ -1,6 +1,12 @@ -## `QPromise::tap` +--- +title: .tap +--- -``` +# QPromise::tap + +*Since: 0.2.0* + +```cpp QPromise::tap(Function handler) -> QPromise ``` diff --git a/docs/qtpromise/qpromise/tapfail.md b/docs/qtpromise/qpromise/tapfail.md index e9b372e..ff88dc0 100644 --- a/docs/qtpromise/qpromise/tapfail.md +++ b/docs/qtpromise/qpromise/tapfail.md @@ -1,6 +1,12 @@ -## `QPromise::tapFail` +--- +title: .tapFail +--- -``` +# QPromise::tapFail + +*Since: 0.4.0* + +```cpp QPromise::tapFail(Function handler) -> QPromise ``` diff --git a/docs/qtpromise/qpromise/then.md b/docs/qtpromise/qpromise/then.md index be55e23..b55ad52 100644 --- a/docs/qtpromise/qpromise/then.md +++ b/docs/qtpromise/qpromise/then.md @@ -1,6 +1,12 @@ -## `QPromise::then` +--- +title: .then +--- -``` +# QPromise::then + +*Since: 0.1.0* + +```cpp QPromise::then(Function onFulfilled, Function onRejected) -> QPromise QPromise::then(Function onFulfilled) -> QPromise ``` @@ -17,9 +23,11 @@ auto output = input.then([](int res) { }); ``` -> **Note**: `onRejected` handler is optional, `output` will be rejected with the same reason as `input`. - -> **Note**: it's recommended to use the [`fail`](fail.md) shorthand to handle errors. +::: tip NOTE +`onRejected` handler is optional, in which case `output` will be rejected with +the same reason as `input`. Also note that it's recommended to use the +[`fail`](fail.md) shorthand to handle errors. +::: The type `` of the `output` promise depends on the return type of the `onFulfilled` handler: @@ -35,7 +43,11 @@ output.then([](const QString& res) { }); ``` -> **Note**: only `onFulfilled` can change the promise type, `onRejected` **must** return the same type as `onFulfilled`. That also means if `onFulfilled` is `nullptr`, `onRejected` must return the same type as the `input` promise. +::: tip NOTE +Only `onFulfilled` can change the promise type, `onRejected` **must** return the +same type as `onFulfilled`. That also means if `onFulfilled` is `nullptr`, +`onRejected` must return the same type as the `input` promise. +::: ```cpp QPromise input = ... diff --git a/docs/qtpromise/qpromise/timeout.md b/docs/qtpromise/qpromise/timeout.md index 8cb3278..3c6e00d 100644 --- a/docs/qtpromise/qpromise/timeout.md +++ b/docs/qtpromise/qpromise/timeout.md @@ -1,6 +1,12 @@ -## `QPromise::timeout` +--- +title: .timeout +--- -``` +# QPromise::timeout + +*Since: 0.2.0* + +```cpp QPromise::timeout(int msec, any error = QPromiseTimeoutException) -> QPromise ``` diff --git a/docs/qtpromise/qpromise/wait.md b/docs/qtpromise/qpromise/wait.md index f2307ac..db9b2c6 100644 --- a/docs/qtpromise/qpromise/wait.md +++ b/docs/qtpromise/qpromise/wait.md @@ -1,6 +1,12 @@ -## `QPromise::wait` +--- +title: .wait +--- -``` +# QPromise::wait + +*Since: 0.1.0* + +```cpp QPromise::wait() -> QPromise ``` diff --git a/docs/qtpromise/qtconcurrent.md b/docs/qtpromise/qtconcurrent.md index c894790..f8858fa 100644 --- a/docs/qtpromise/qtconcurrent.md +++ b/docs/qtpromise/qtconcurrent.md @@ -1,4 +1,4 @@ -## QtConcurrent +# QtConcurrent QtPromise integrates with [QtConcurrent](https://doc.qt.io/qt-5/qtconcurrent-index.html) to make easy chaining QFuture with QPromise. diff --git a/docs/qtpromise/thread-safety.md b/docs/qtpromise/thread-safety.md index b4eee3c..426f131 100644 --- a/docs/qtpromise/thread-safety.md +++ b/docs/qtpromise/thread-safety.md @@ -1,5 +1,7 @@ -## Thread-Safety +# Thread-Safety QPromise is thread-safe and can be copied and accessed across different threads. QPromise relies on [explicitly data sharing](https://doc.qt.io/qt-5/qexplicitlyshareddatapointer.html#details) and thus `auto p2 = p1` represents the same promise: when `p1` resolves, handlers registered on `p1` and `p2` are called, the fulfilled value being shared between both instances. -> **Note:** while it's safe to access the resolved value from different threads using [`then`](qpromise/then.md), QPromise provides no guarantee about the object being pointed to. Thread-safety and reentrancy rules for that object still apply. +::: warning IMPORTANT +While it's safe to access the resolved value from different threads using [`then`](qpromise/then.md), QPromise provides no guarantee about the object being pointed to. Thread-safety and reentrancy rules for that object still apply. +:::