Documentation Home >> Headers >> <jss/experimental_future.hpp> Header >> std::experimental::future >> std::experimental::future<>::then Member function

Schedule a function to be invoked when *this becomes ready.

template<typename Func>
future<std::result_of<Func(ResultType)>::type> then(
    Func&& func);

template<typename Func>
future<std::result_of<Func(ResultType)>::type> then(
    std::launch policy,Func&& func);

Preconditions:

this->valid() would return true. func(this->get()) is valid. Func is MoveConstructible.

Effects:

If the asynchronous result associated with *this contains a deferred function arising from a call to std::experimental::async that has not yet started execution, invokes the deferred function.

Copies func to internal storage.

If *this is ready, schedules func immediately. Otherwise, func is scheduled when the asynchronous result associated with *this becomes ready.

When func is scheduled, it is scheduled as-if std::async(policy,func,this->get()). If policy is not specified in the call to then, the policy is given the value used when creating the asynchronous result associated with *this, if any, or std::launch::deferred | std::launch::async if the asynchronous result associated with *this does not have an associated launch policy.

Returns:

A new instance of std::experimental::future associated with a newly-created asynchronous result to be populated with the return value or any exception thrown by the invocation of func.

Throws:

std::bad_alloc if the required internal storage cannot be allocated, otherwise std::future_error when the effects cannot be achieved, or any exception thrown during the copy of func to internal storage.

Postcondition:

this->valid() returns false.

Header

#include <experimental/future>

See Also