Documentation Home >> Headers >> <jss/experimental_future.hpp> Header >> std::experimental::when_any function template

std::experimental::when_any combines a set of futures into a single future that becomes ready when any of the futures in the set become ready.

template<typename ... FutureTypes>
std::experimental::future<std::experimental::when_any_result<std::tuple<FutureTypes...> > >
when_any(FutureTypes&&... futures);

Preconditions:

Each type in FutureTypes is an instantiation of either std::experimental::future or std::experimental::shared_future. For each value in futures a call to valid() must return true. Any future which is an instantation of std::experimental::future must be passed as an rvalue.

Effects:

The supplied futures are transferred into internal storage. The asynchronous result associated with each future is marked so that when any of the futures are ready the future returned from when_any is ready. If any of the futures are already ready at the point of the call, the returned future will also be ready.

Returns:

A std::experimental::future<std::experimental::when_any_result<std::tuple<FutureTypes> > > which becomes ready when any of the supplied futures becomes ready. When the future is ready, the stored value's sequence member is a std::tuple holding the supplied futures, and the index member holds the index of the future that caused the result to become 'ready.

Synchronization:

The marking of the first future as ready synchronizes with any call to wait() or get() on the returned future that sees the result as ready.

Throws:

std::bad_alloc if the required internal storage cannot be allocated.

Header

#include <experimental/future>

See Also