mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-23 11:17:12 +08:00
Add documentation for built-in exceptions
This commit is contained in:
parent
fa5a4192ff
commit
9119cc72f6
@ -52,6 +52,14 @@ module.exports = {
|
||||
'qtpromise/helpers/qpromise',
|
||||
'qtpromise/helpers/qpromiseall'
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'Exceptions',
|
||||
children: [
|
||||
'qtpromise/exceptions/canceled',
|
||||
'qtpromise/exceptions/timeout',
|
||||
'qtpromise/exceptions/undefined'
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -32,3 +32,9 @@
|
||||
* [`QtPromise::map`](helpers/map.md)
|
||||
* [`qPromise`](helpers/qpromise.md)
|
||||
* [`qPromiseAll`](helpers/qpromiseall.md)
|
||||
|
||||
## Exceptions
|
||||
|
||||
* [`QPromiseCanceledException`](exceptions/canceled.md)
|
||||
* [`QPromiseTimeoutException`](exceptions/timeout.md)
|
||||
* [`QPromiseUndefinedException`](exceptions/undefined.md)
|
||||
|
19
docs/qtpromise/exceptions/canceled.md
Normal file
19
docs/qtpromise/exceptions/canceled.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
title: QPromiseCanceledException
|
||||
---
|
||||
|
||||
# QPromiseCanceledException
|
||||
|
||||
*Since: 0.1.0*
|
||||
|
||||
This exception is thrown for promise created from a [`QFuture`](../qtconcurrent.md)
|
||||
which has been canceled (e.g. using [`QFuture::cancel()`](http://doc.qt.io/qt-5/qfuture.html#cancel)).
|
||||
Note that QtPromise doesn't support promise cancelation yet. For example:
|
||||
|
||||
```cpp
|
||||
auto output = qPromise(future)
|
||||
.fail([](const QPromiseCanceledException&) {
|
||||
// `future` has been canceled!
|
||||
});
|
||||
```
|
||||
|
18
docs/qtpromise/exceptions/timeout.md
Normal file
18
docs/qtpromise/exceptions/timeout.md
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
title: QPromiseTimeoutException
|
||||
---
|
||||
|
||||
# QPromiseTimeoutException
|
||||
|
||||
*Since: 0.2.0*
|
||||
|
||||
This is the default exception thrown when reaching the time limit when using
|
||||
the [`QPromise::timeout()`](../qpromise/timeout.md) method, for example:
|
||||
|
||||
```cpp
|
||||
QPromise<int> input = {...}
|
||||
auto output = input.timeout(2000)
|
||||
.fail([](const QPromiseTimeoutException& e) {
|
||||
// operation timed out after 2s!
|
||||
});
|
||||
```
|
26
docs/qtpromise/exceptions/undefined.md
Normal file
26
docs/qtpromise/exceptions/undefined.md
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
title: QPromiseUndefinedException
|
||||
---
|
||||
|
||||
# QPromiseUndefinedException
|
||||
|
||||
*Since: 0.5.0*
|
||||
|
||||
This exception is thrown when rejecting a promise with no explicit reason, for
|
||||
example:
|
||||
|
||||
```cpp
|
||||
QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
||||
async_method([=](bool success, int result) {
|
||||
if (success) {
|
||||
resolve(result);
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
promise.fail([](const QPromiseUndefinedException&) {
|
||||
// promise rejected without reason!
|
||||
})
|
||||
```
|
@ -42,7 +42,7 @@ QPromise<int> promise([](const auto& resolve, const auto& reject) {
|
||||
|
||||
While not recommended because it makes tracking errors more difficult, it's also
|
||||
possible to reject a promise without explicit reason, in which case, a built-in
|
||||
`QPromiseUndefinedException` is thrown:
|
||||
[`QPromiseUndefinedException`](../exceptions/undefined.md) is thrown:
|
||||
|
||||
```cpp
|
||||
QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
||||
|
@ -10,7 +10,7 @@ title: .timeout
|
||||
QPromise<T>::timeout(int msec, any error = QPromiseTimeoutException) -> QPromise<T>
|
||||
```
|
||||
|
||||
This method returns a promise that will be resolved with the `input` promise's fulfillment value or rejection reason. However, if the `input` promise is not fulfilled or rejected within `msec` milliseconds, the `output` promise is rejected with `error` as the reason (`QPromiseTimeoutException` by default).
|
||||
This method returns a promise that will be resolved with the `input` promise's fulfillment value or rejection reason. However, if the `input` promise is not fulfilled or rejected within `msec` milliseconds, the `output` promise is rejected with `error` as the reason ([`QPromiseTimeoutException`](../exceptions/timeout.md) by default).
|
||||
|
||||
```cpp
|
||||
QPromise<int> input = {...}
|
||||
|
Loading…
Reference in New Issue
Block a user