Enhance QPromise<T>::wait documentation

This commit is contained in:
Simon Brunel 2018-02-17 13:00:21 +01:00
parent 9d2a4ca00f
commit f794916be6
2 changed files with 9 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
_book
dist
node_modules
*.gcno

View File

@ -4,18 +4,20 @@
QPromise<T>::wait() -> QPromise<T>
```
This method holds the execution of the remaining code **without** blocking the event loop of the current thread:
This method holds the execution of the remaining code until the `input` promise is resolved (either fulfilled or rejected), **without** blocking the event loop of the current thread:
```cpp
int result = -1;
QPromise<int> input = qPromise(QtConcurrent::run([]() { return 42; }));
auto output = input.then([&](int res) {
QPromise<int> input = qPromise(QtConcurrent::run([]() {
return 42;
})).tap([&](int res) {
result = res;
});
// output.isPending() is true && result is -1
// input.isPending() is true && result is -1
output.wait();
input.wait();
// output.isPending() is false && result is 42
// input.isPending() is false && result is 42
```