public member function
<future>

std::shared_future::wait_for

template <class Rep, class Period>
  future_status wait_for (const chrono::duration<Rep,Period>& rel_time) const;
Wait for ready during time span
Waits for the shared state to be ready for up to the time specified by rel_time.

If the shared state is not yet ready (i.e., the provider has not yet set its value or exception), the function blocks the calling thread and waits until it is ready or until rel_time has elapsed, whichever happens first.

When the function returns because its shared state is made ready, the value or exception set on the shared state is not read, but all visible side effects are synchronized between the point the provider makes the shared state ready and the return of this function.

If the shared state contains a deferred function, the function does not block, returning immediately with a value of future_status::deferred.

Parameters

rel_time
The time span after which the function returns resuming execution of the calling thread.
Note that multi-threading management operations may cause certain delays beyond this.
duration is an object that represents a specific relative time.

Return value

A value of type future_status indicating what caused the function to return:
valuedescription
future_status::readyThe shared state is ready: the producer has set a value or exception.
future_status::timeoutThe function waited for rel_time without the shared state becoming ready.
future_status::deferredThe shared state contains a deferred function.

Data races

The future object is accessed.
The shared state is accessed as an atomic operation (causing no data races).

Exception safety

Calling this member function on a shared_future object that is not valid, produces undefined behavior (although library implementations may detect this and throw future_error with a no_state error condition, offering a strong guarantee).

It may throw if an operation related to rel_time throws (note that operations on duration types provided in <chrono>, such as seconds, never throw).

See also