std::shared_future::wait_for - cppreference.com (original) (raw)

Waits for the result to become available. Blocks until specified timeout_duration has elapsed or the result becomes available, whichever comes first. The return value identifies the state of the result.

If the future is the result of a call to std::async that used lazy evaluation, this function returns immediately without waiting.

This function may block for longer than timeout_duration due to scheduling or resource contention delays.

The standard recommends that a steady clock is used to measure the duration. If an implementation uses a system clock instead, the wait time may also be sensitive to clock adjustments.

The behavior is undefined if valid() is false before the call to this function.

[edit] Parameters

timeout_duration - maximum duration to block for

[edit] Return value

[edit] Exceptions

Any exception thrown by clock, time_point, or duration during the execution (clocks, time points, and durations provided by the standard library never throw).

[edit] Notes

The implementations are encouraged to detect the case when valid == false before the call and throw a std::future_error with an error condition of std::future_errc::no_state.

[edit] Example

Possible output:

waiting... timeout timeout timeout ready! result is 8

[edit] See also

| | waits for the result to become available (public member function) [edit] | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | waits for the result, returns if it is not available until specified time point has been reached (public member function) [edit] |