Documentation Home >> Headers >> <future> Header >> std::shared_future >> std::shared_future<>::wait_for Member function

Wait until the asynchronous result associated with an instance of std::shared_future is ready, or until a specified time period has elapsed.

template<typename Rep,typename Period>
future_status wait_for(
    std::chrono::duration<Rep,Period> const&
    relative_time) const;

Preconditions:

this->valid() would return true.

Effects:

If the asynchronous result associated with *this contains a deferred function arising from a call to std::async that has not yet started execution, returns immediately without blocking. Otherwise blocks until the asynchronous result associated with *this is ready or the time period specified by relative_time has elapsed.

Returns:

std::future_status::deferred if the asynchronous result associated with *this contains a deferred function arising from a call to std::async that has not yet started execution, std::future_status::ready if the asynchronous result associated with *this is ready, std::future_status::timeout if the time period specified by relative_time has elapsed.

Note:

The thread may be blocked for longer than the specified duration. Where possible, the elapsed time is determined by a steady clock.

Throws:

Nothing.

Header

#include <future>

See Also