qtpromise/docs/qtpromise/qpromise/constructor.md
Simon Brunel 18739bd8e0 New documentation based on GitBook CLI
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
2018-02-11 19:02:14 +01:00

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) {
// {...}
});
```