mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2025-07-02 23:35:26 +08:00
Implement QPromise::tapFail(handler)
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
* [.isPending](qtpromise/qpromise/ispending.md)
|
||||
* [.isRejected](qtpromise/qpromise/isrejected.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)
|
||||
|
@ -10,6 +10,7 @@
|
||||
* [`QPromise<T>::isPending`](qpromise/ispending.md)
|
||||
* [`QPromise<T>::isRejected`](qpromise/isrejected.md)
|
||||
* [`QPromise<T>::tap`](qpromise/tap.md)
|
||||
* [`QPromise<T>::tapFail`](qpromise/tapfail.md)
|
||||
* [`QPromise<T>::then`](qpromise/then.md)
|
||||
* [`QPromise<T>::timeout`](qpromise/timeout.md)
|
||||
* [`QPromise<T>::wait`](qpromise/wait.md)
|
||||
|
21
docs/qtpromise/qpromise/tapfail.md
Normal file
21
docs/qtpromise/qpromise/tapfail.md
Normal file
@ -0,0 +1,21 @@
|
||||
## `QPromise<T>::tapFail`
|
||||
|
||||
```
|
||||
QPromise<T>::tapFail(Function handler) -> QPromise<T>
|
||||
```
|
||||
|
||||
This `handler` allows to observe errors of the `input` promise without handling them - similar to [`finally`](finally.md) but **only** called on rejections. The `output` promise has the same type as the `input` one but also the same value or error. However, if `handler` throws, `output` is rejected with the new exception.
|
||||
|
||||
```cpp
|
||||
QPromise<int> input = {...}
|
||||
auto output = input.tapFail([](Error err) {
|
||||
log(err);
|
||||
}).then([](int res) {
|
||||
return process(res);
|
||||
}).fail([](Error err) {
|
||||
handle(err);
|
||||
return -1;
|
||||
});
|
||||
```
|
||||
|
||||
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.
|
Reference in New Issue
Block a user