mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-21 18:24:29 +08:00
Enhance QPromise<T>::wait
documentation
This commit is contained in:
parent
9d2a4ca00f
commit
f794916be6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
_book
|
||||
dist
|
||||
node_modules
|
||||
*.gcno
|
||||
|
@ -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
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user