mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2025-04-11 03:21:29 +08:00
Split the root README.md in multiple Markdown files (in the `docs/` folder) to make easier reading, editing and extending the documentation. An online version is also available on netlify (https://qtpromise.netlify.com). Building it requires Node.js installed, then: - npm install -g gitbook-cli - gitbook install ./ - gitbook build . dist/docs
30 lines
691 B
Markdown
30 lines
691 B
Markdown
## `QPromise<T>::QPromise`
|
|
|
|
```
|
|
QPromise<T>::QPromise(Function resolver)
|
|
```
|
|
|
|
Creates a new promise that will be fulfilled or rejected by the given `resolver` lambda:
|
|
|
|
```cpp
|
|
QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
|
|
async_method([=](bool success, int result) {
|
|
if (success) {
|
|
resolve(result);
|
|
} else {
|
|
reject(customException());
|
|
}
|
|
});
|
|
});
|
|
```
|
|
|
|
> **Note:** `QPromise<void>` is specialized to not contain any value, meaning that the `resolve` callback takes no argument.
|
|
|
|
**C++14**
|
|
|
|
```cpp
|
|
QPromise<int> promise([](const auto& resolve, const auto& reject) {
|
|
// {...}
|
|
});
|
|
```
|