Allow undefined rejection reason

While not recommended because it makes tracking errors more difficult, it's now possible to reject a promise without explicit reason, in which case, a built-in `QPromiseUndefinedException` is thrown. This is done in anticipation of handling rejection signals without argument.
This commit is contained in:
Simon Brunel
2019-01-31 17:59:39 +01:00
parent 16229fc2c9
commit fa5a4192ff
5 changed files with 96 additions and 0 deletions

View File

@ -35,3 +35,35 @@ QPromise<int> promise([](const auto& resolve, const auto& reject) {
// {...}
});
```
**Undefined rejection reason**
*Since: 0.5.0*
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:
```cpp
QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
async_method([=](bool success, int result) {
if (success) {
resolve(result);
} else {
reject();
}
});
});
```
```cpp
// The exception can be caught explicitly
promise.fail([](const QPromiseUndefinedException&) {
// { ... }
})
// ... or implicitly (since undefined)
promise.fail([]() {
// { ... }
})
```