Skip to content

Commit 81063b0

Browse files
committed
Modified future-and-promise.md to include notes about waiting mechanisms
1 parent a96267c commit 81063b0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

future-and-promise.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,22 @@ async_packaged(Function&& function, Args&&... args) {
158158
return future;
159159
}
160160
```
161+
162+
## Waiting for Futures
163+
164+
One thing to mention here is that there exist two other ways of waiting for a
165+
future other than the plain `wait()`. These two are:
166+
167+
1. `std::future::wait_for`, which waits for a given (`std::chrono`) duration.
168+
2. `std::future::wait_until`, which waits until a given (`std::chrono`)
169+
time-point.
170+
171+
Both of these methods return one of three codes upon finishing:
172+
173+
1. `std::future_status::ready`: The future is ready.
174+
2. `std::future_status::timeout`: The future was not yet ready after waiting.
175+
3. `std::future_status::deferred`: The future is actually deferred and was not
176+
yet started.
177+
178+
Note that for (1) `std::chrono` literals are especially nice
179+
(`future.wait_for(100ns)`).

0 commit comments

Comments
 (0)