Differential D18758 Diff 58398 kdevplatform/3rdparty/qtpromise/qtpromise-0.5.0/docs/qtpromise/qpromise/tap.md
Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/3rdparty/qtpromise/qtpromise-0.5.0/docs/qtpromise/qpromise/tap.md
- This file was added.
1 | --- | ||||
---|---|---|---|---|---|
2 | title: .tap | ||||
3 | --- | ||||
4 | | ||||
5 | # QPromise::tap | ||||
6 | | ||||
7 | *Since: 0.2.0* | ||||
8 | | ||||
9 | ```cpp | ||||
10 | QPromise<T>::tap(Function handler) -> QPromise<T> | ||||
11 | ``` | ||||
12 | | ||||
13 | This `handler` allows to observe the value of the `input` promise, without changing the propagated value. The `output` promise will be resolved with the same value as the `input` promise (the `handler` returned value will be ignored). However, if `handler` throws, `output` is rejected with the new exception. Unlike [`finally`](finally.md), this handler is **not** called for rejections. | ||||
14 | | ||||
15 | ```cpp | ||||
16 | QPromise<int> input = {...} | ||||
17 | auto output = input.tap([](int res) { | ||||
18 | log(res); | ||||
19 | }).then([](int res) { | ||||
20 | // {...} | ||||
21 | }); | ||||
22 | ``` | ||||
23 | | ||||
24 | If `handler` returns a promise (or QFuture), the `output` promise is delayed until the returned promise is resolved and under the same conditions: the delayed value is ignored, the error transmitted to the `output` promise. |