mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-22 02:34:30 +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
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
*.gcno
|
*.gcno
|
||||||
|
@ -4,18 +4,20 @@
|
|||||||
QPromise<T>::wait() -> QPromise<T>
|
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
|
```cpp
|
||||||
int result = -1;
|
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;
|
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