Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

when_any Function

Creates a task that will complete successfully when any of the tasks supplied as arguments completes successfully.

template<
   typename _Iterator
>
auto when_any(
   _Iterator_Begin,
   _Iterator_End,
   const task_options& _TaskOptions = task_options()
) -> decltype (details::_WhenAnyImpl<typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_TaskOptions, _Begin, _End));

template<
   typename _Iterator
>
auto when_any(
   _Iterator_Begin,
   _Iterator_End,
   cancellation_token _CancellationToken
) -> decltype (details::_WhenAnyImpl<typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_CancellationToken._GetImplValue(), _Begin, _End));
_Iterator

The type of the input iterator.

_Begin

The position of the first element in the range of elements to be combined into the resulting task.

_End

The position of the first element beyond the range of elements to be combined into the resulting task.

_TaskOptions
_CancellationToken

The cancellation token which controls cancellation of the returned task. If you do not provide a cancellation token, the resulting task will receive the cancellation token of the task that causes it to complete.

A task that completes successfully when any one of the input tasks has completed successfully. If the input tasks are of type T, the output of this function will be a task<std::pair<T, size_t>>>, where the first element of the pair is the result of the completing task, and the second element is the index of the task that finished. If the input tasks are of type void the output is a task<size_t>, where the result is the index of the completing task.

when_any is a non-blocking function that produces a task as its result. Unlike task::wait, it is safe to call this function in a Windows Store app on the ASTA (Application STA) thread.

For more information, see Task Parallelism (Concurrency Runtime).

Header: ppltasks.h

Namespace: concurrency

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.