STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Concurrency::task< _ReturnType > Class Template Reference

The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed asynchronously, and concurrently with other tasks and parallel work produced by parallel algorithms in the Concurrency Runtime. It produces a result of type _ResultType on successful completion. Tasks of type task<void> produce no result. A task can be waited upon and canceled independently of other tasks. It can also be composed with other tasks using continuations(then), and join(when_all) and choice(when_any) patterns. More...

#include <ppltasks.h>

Classes

struct  _ContinuationTaskHandle
 The task handle type used to create a 'continuation task'. More...
 
struct  _InitialTaskHandle
 

Public Types

typedef _ReturnType result_type
 The type of the result an object of this class produces. More...
 

Public Member Functions

 task ()
 Constructs a task object. More...
 
template<typename _Ty >
 __declspec (noinline) explicit task(_Ty _Param)
 Constructs a task object. More...
 
template<typename _Ty >
 __declspec (noinline) explicit task(_Ty _Param
 Constructs a task object. More...
 
 _CreateImpl (_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler())
 
 _SetTaskCreationCallstack (details::_get_internal_task_options(_TaskOptions)._M_hasPresetCreationCallstack?details::_get_internal_task_options(_TaskOptions)._M_presetCreationCallstack:_CAPTURE_CALLSTACK())
 
 _TaskInitMaybeFunctor (_Param, decltype(details::_IsCallable(_Param, 0))())
 
 task (const task &_Other)
 Constructs a task object. More...
 
 task (task &&_Other)
 Constructs a task object. More...
 
taskoperator= (const task &_Other)
 Replaces the contents of one task object with another. More...
 
taskoperator= (task &&_Other)
 Replaces the contents of one task object with another. More...
 
template<typename _Function >
 __declspec (noinline) auto then(const _Function &_Func) const -> typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_TaskOfType
 Adds a continuation task to this task. More...
 
template<typename _Function >
 __declspec (noinline) auto then(const _Function &_Func
 Adds a continuation task to this task. More...
 
return _ThenImpl (typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_StdFuncT(_Func), _Options)
 
template<typename _Function >
 __declspec (noinline) auto then(const _Function &_Func
 Adds a continuation task to this task. More...
 
 details::_get_internal_task_options (_TaskOptions)._set_creation_callstack(_CAPTURE_CALLSTACK())
 
return _ThenImpl (typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_StdFuncT(_Func), _Options)
 
task_status wait () const
 Waits for this task to reach a terminal state. It is possible for wait to execute the task inline, if all of the tasks dependencies are satisfied, and it has not already been picked up for execution by a background worker. More...
 
_ReturnType get () const
 Returns the result this task produced. If the task is not in a terminal state, a call to get will wait for the task to finish. This method does not return a value when called on a task with a result_type of void. More...
 
bool is_done () const
 Determines if the task is completed. More...
 
scheduler_ptr scheduler () const
 Returns the scheduler for this task More...
 
bool is_apartment_aware () const
 Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such a task. More...
 
bool operator== (const task< _ReturnType > &_Rhs) const
 Determines whether two task objects represent the same internal task. More...
 
bool operator!= (const task< _ReturnType > &_Rhs) const
 Determines whether two task objects represent different internal tasks. More...
 
void _CreateImpl (details::_CancellationTokenState *_Ct, scheduler_ptr _Scheduler)
 Create an underlying task implementation. More...
 
const details::_Task_ptr< _ReturnType >::_Type_GetImpl () const
 Return the underlying implementation for this task. More...
 
const details::_Task_ptr< _ReturnType >::_Type_ThenGetImpl () const
 
void _SetImpl (const typename details::_Task_ptr< _ReturnType >::_Type &_Impl)
 Set the implementation of the task to be the supplied implementation. More...
 
void _SetImpl (typename details::_Task_ptr< _ReturnType >::_Type &&_Impl)
 Set the implementation of the task to be the supplied implementation using a move instead of a copy. More...
 
void _SetAsync (bool _Async=true)
 Sets a property determining whether the task is apartment aware. More...
 
void _SetTaskCreationCallstack (const details::_TaskCreationCallstack &_callstack)
 Sets a field in the task impl to the return callstack for calls to the task constructors and the then method. More...
 
template<typename _Function >
auto _Then (const _Function &_Func, details::_CancellationTokenState *_PTokenState, details::_TaskInliningMode_t _InliningMode=details::_ForceInline) const -> typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_TaskOfType
 An internal version of then that takes additional flags and always execute the continuation inline by default. When _ForceInline is set to false, continuations inlining will be limited to default _DefaultAutoInline. This function is Used for runtime internal continuations only. More...
 

Public Attributes

const task_options_TaskOptions
 
auto _ContinuationContext = _TaskOptions.get_continuation_context()
 
auto _Options = details::_ThenImplOptions::_CreateOptions(_TaskOptions, _ContinuationContext, _ThenGetImpl()->_GetScheduler())
 
cancellation_token _CancellationToken
 

Private Member Functions

template<typename _InternalReturnType , typename _Function >
void _TaskInitWithFunctor (const _Function &_Func)
 Initializes a task using a lambda, function pointer or function object. More...
 
void _TaskInitNoFunctor (task_completion_event< _ReturnType > &_Event)
 Initializes a task using a task completion event. More...
 
template<typename _Function >
void _TaskInitMaybeFunctor (_Function &_Func, std::true_type)
 Initializes a task using a callable object. More...
 
template<typename _Ty >
void _TaskInitMaybeFunctor (_Ty &_Param, std::false_type)
 Initializes a task using a non-callable object. More...
 
template<typename _InternalReturnType , typename _Function >
auto _ThenImpl (const _Function &_Func, details::_ThenImplOptions &_Options) const -> typename details::_ContinuationTypeTraits< _Function, _InternalReturnType >::_TaskOfType
 The one and only implementation of then for void and non-void tasks. More...
 

Private Attributes

details::_Task_ptr< _ReturnType >::_Type _M_Impl
 

Friends

template<typename _Ty >
class task
 

Detailed Description

template<typename _ReturnType>
class Concurrency::task< _ReturnType >

The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed asynchronously, and concurrently with other tasks and parallel work produced by parallel algorithms in the Concurrency Runtime. It produces a result of type _ResultType on successful completion. Tasks of type task<void> produce no result. A task can be waited upon and canceled independently of other tasks. It can also be composed with other tasks using continuations(then), and join(when_all) and choice(when_any) patterns.

Template Parameters
_ReturnTypeThe result type of this task.

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

Member Typedef Documentation

template<typename _ReturnType>
typedef _ReturnType Concurrency::task< _ReturnType >::result_type

The type of the result an object of this class produces.

Constructor & Destructor Documentation

template<typename _ReturnType>
Concurrency::task< _ReturnType >::task ( )
inline

Constructs a task object.

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

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

2912  : _M_Impl(nullptr)
2913  {
2914  // The default constructor should create a task with a nullptr impl. This is a signal that the
2915  // task is not usable and should throw if any wait(), get() or then() APIs are used.
2916  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
Concurrency::task< _ReturnType >::task ( const task< _ReturnType > &  _Other)
inline

Constructs a task object.

Parameters
_OtherThe source task object.

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

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

3039 : _M_Impl(_Other._M_Impl) {}
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
Concurrency::task< _ReturnType >::task ( task< _ReturnType > &&  _Other)
inline

Constructs a task object.

Parameters
_OtherThe source task object.

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

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

3066 : _M_Impl(std::move(_Other._M_Impl)) {}
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1349

Member Function Documentation

template<typename _ReturnType>
template<typename _Ty >
Concurrency::task< _ReturnType >::__declspec ( noinline  )
inline

Constructs a task object.

Template Parameters
_TyThe type of the parameter from which the task is to be constructed.
Parameters
_ParamThe parameter from which the task is to be constructed. This could be a lambda, a function object, a task_completion_event<result_type> object, or a Windows::Foundation::IAsyncInfo if you are using tasks in your Windows Store app. The lambda or function object should be a type equivalent to std::function<X(void)>, where X can be a variable of type result_type, task<result_type>, or a Windows::Foundation::IAsyncInfo in Windows Store apps.
_TokenThe cancellation token to associate with this task. A task created without a cancellation token cannot be canceled. It implicitly receives the token cancellation_token::none().

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

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

2956  {
2957  task_options _TaskOptions;
2958  details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param);
2959 
2960  _CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler());
2961  // Do not move the next line out of this function. It is important that _CAPTURE_CALLSTACK() evaluates to the call site of the task constructor.
2963 
2964  _TaskInitMaybeFunctor(_Param, decltype(details::_IsCallable(_Param,0))());
2965  }
const task_options & _TaskOptions
Definition: ppltasks.h:3004
auto _IsCallable(_Function _Func, int) -> decltype(_Func(), std::true_type())
_TaskInitMaybeFunctor(_Param, decltype(details::_IsCallable(_Param, 0))())
_SetTaskCreationCallstack(details::_get_internal_task_options(_TaskOptions)._M_hasPresetCreationCallstack?details::_get_internal_task_options(_TaskOptions)._M_presetCreationCallstack:_CAPTURE_CALLSTACK())
#define _CAPTURE_CALLSTACK()
Helper macro to determine how many stack frames need to be saved. When any number less or equal to 1 ...
Definition: ppltasks.h:118
_CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler())
template<typename _ReturnType>
template<typename _Ty >
Concurrency::task< _ReturnType >::__declspec ( noinline  )

Constructs a task object.

Template Parameters
_TyThe type of the parameter from which the task is to be constructed.
Parameters
_ParamThe parameter from which the task is to be constructed. This could be a lambda, a function object, a task_completion_event<result_type> object, or a Windows::Foundation::IAsyncInfo if you are using tasks in your Windows Store app. The lambda or function object should be a type equivalent to std::function<X(void)>, where X can be a variable of type result_type, task<result_type>, or a Windows::Foundation::IAsyncInfo in Windows Store apps.
_TaskOptionsThe task options include cancellation token, scheduler etc

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

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

template<typename _ReturnType>
template<typename _Function >
Concurrency::task< _ReturnType >::__declspec ( noinline  ) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
inline

Adds a continuation task to this task.

Template Parameters
_FunctionThe type of the function object that will be invoked by this task.
Parameters
_FuncThe continuation function to execute when this task completes. This continuation function must take as input a variable of either result_type or task<result_type>, where result_type is the type of the result this task produces.
Returns
The newly created continuation task. The result type of the returned task is determined by what _Func returns.

The overloads of then that take a lambda or functor that returns a Windows::Foundation::IAsyncInfo interface, are only available to Windows Store apps.

For more information on how to use task continuations to compose asynchronous work, see Task Parallelism (Concurrency Runtime).

3131  {
3132  task_options _TaskOptions;
3134 
3135  // Note: _ThenImpl's implementation makes a copy of the continuation_context when it schedules the continuation.
3136  // The Continuation Context used to create the _ThenImplOptions must still exist when _ThenImpl executes.
3137  auto _ContinuationContext = _TaskOptions.get_continuation_context();
3138  auto _Options = details::_ThenImplOptions::_CreateOptions(_TaskOptions, _ContinuationContext, _ThenGetImpl()->_GetScheduler());
3139 
3140 #ifndef _PPLTASKS_NO_STDFUNC
3141  return _ThenImpl<_ReturnType>(typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_StdFuncT(_Func), _Options);
3142 #else
3143  return _ThenImpl<_ReturnType>(_Func, _Options);
3144 #endif
3145  }
void _set_creation_callstack(const _TaskCreationCallstack &_callstack)
Definition: ppltasks.h:1043
const task_options & _TaskOptions
Definition: ppltasks.h:3004
const details::_Task_ptr< _ReturnType >::_Type & _ThenGetImpl() const
Definition: ppltasks.h:3376
_Internal_task_options & _get_internal_task_options(task_options &_Options)
Definition: ppltasks.h:1267
auto _Options
Definition: ppltasks.h:3180
auto _ContinuationContext
Definition: ppltasks.h:3179
static _ThenImplOptions _CreateOptions(const task_options &_Task_Options, const task_continuation_context &_ContinuationContext, const scheduler_ptr &impl_scheduler)
Definition: ppltasks.h:1251
#define _CAPTURE_CALLSTACK()
Helper macro to determine how many stack frames need to be saved. When any number less or equal to 1 ...
Definition: ppltasks.h:118
std::function< _RetTypeT __cdecl(_ArgTypeT)> _StdFuncT
Definition: ppltasks.h:407
template<typename _ReturnType>
template<typename _Function >
Concurrency::task< _ReturnType >::__declspec ( noinline  ) const

Adds a continuation task to this task.

Template Parameters
_FunctionThe type of the function object that will be invoked by this task.
Parameters
_FuncThe continuation function to execute when this task completes. This continuation function must take as input a variable of either result_type or task<result_type>, where result_type is the type of the result this task produces.
_TaskOptionsThe task options include cancellation token, scheduler and continuation context. By default the former 3 options are inherited from the antecedent task
Returns
The newly created continuation task. The result type of the returned task is determined by what _Func returns.

The overloads of then that take a lambda or functor that returns a Windows::Foundation::IAsyncInfo interface, are only available to Windows Store apps.

For more information on how to use task continuations to compose asynchronous work, see Task Parallelism (Concurrency Runtime).

template<typename _ReturnType>
template<typename _Function >
Concurrency::task< _ReturnType >::__declspec ( noinline  ) const

Adds a continuation task to this task.

Template Parameters
_FunctionThe type of the function object that will be invoked by this task.
Parameters
_FuncThe continuation function to execute when this task completes. This continuation function must take as input a variable of either result_type or task<result_type>, where result_type is the type of the result this task produces.
_CancellationTokenThe cancellation token to associate with the continuation task. A continuation task that is created without a cancellation token will inherit the token of its antecedent task.
_ContinuationContextA variable that specifies where the continuation should execute. This variable is only useful when used in a Windows Store style app. For more information, see task_continuation_context
Returns
The newly created continuation task. The result type of the returned task is determined by what _Func returns.

The overloads of then that take a lambda or functor that returns a Windows::Foundation::IAsyncInfo interface, are only available to Windows Store apps.

For more information on how to use task continuations to compose asynchronous work, see Task Parallelism (Concurrency Runtime).

template<typename _ReturnType>
Concurrency::task< _ReturnType >::_CreateImpl ( _TaskOptions.  get_cancellation_token)._GetImplValue(,
_TaskOptions.  get_scheduler() 
)
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_CreateImpl ( details::_CancellationTokenState _Ct,
scheduler_ptr  _Scheduler 
)
inline

Create an underlying task implementation.

3359  {
3360  _ASSERTE(_Ct != nullptr);
3363  {
3364  _M_Impl->_RegisterCancellation(_M_Impl);
3365  }
3366  }
#define _ASSERTE(expr)
Definition: crtdbg.h:707
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:332
static _Type _Make(_CancellationTokenState *_Ct, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:1283
template<typename _ReturnType>
const details::_Task_ptr<_ReturnType>::_Type& Concurrency::task< _ReturnType >::_GetImpl ( ) const
inline

Return the underlying implementation for this task.

3372  {
3373  return _M_Impl;
3374  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_SetAsync ( bool  _Async = true)
inline

Sets a property determining whether the task is apartment aware.

3408  {
3409  _GetImpl()->_SetAsync(_Async);
3410  }
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3371
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_SetImpl ( const typename details::_Task_ptr< _ReturnType >::_Type _Impl)
inline

Set the implementation of the task to be the supplied implementation.

3390  {
3391  _ASSERTE(!_M_Impl);
3392  _M_Impl = _Impl;
3393  }
#define _ASSERTE(expr)
Definition: crtdbg.h:707
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_SetImpl ( typename details::_Task_ptr< _ReturnType >::_Type &&  _Impl)
inline

Set the implementation of the task to be the supplied implementation using a move instead of a copy.

3399  {
3400  _ASSERTE(!_M_Impl);
3401  _M_Impl = std::move(_Impl);
3402  }
#define _ASSERTE(expr)
Definition: crtdbg.h:707
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1349
template<typename _ReturnType>
Concurrency::task< _ReturnType >::_SetTaskCreationCallstack ( details::  _get_internal_task_options_TaskOptions)._M_hasPresetCreationCallstack?details::_get_internal_task_options(_TaskOptions)._M_presetCreationCallstack:_CAPTURE_CALLSTACK()
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_SetTaskCreationCallstack ( const details::_TaskCreationCallstack _callstack)
inline

Sets a field in the task impl to the return callstack for calls to the task constructors and the then method.

3416  {
3417  _GetImpl()->_SetTaskCreationCallstack(_callstack);
3418  }
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3371
template<typename _ReturnType>
Concurrency::task< _ReturnType >::_TaskInitMaybeFunctor ( _Param  ,
decltype(details::_IsCallable(_Param, 0))()   
)
template<typename _ReturnType>
template<typename _Function >
void Concurrency::task< _ReturnType >::_TaskInitMaybeFunctor ( _Function &  _Func,
std::true_type   
)
inlineprivate

Initializes a task using a callable object.

3829  {
3830  _TaskInitWithFunctor<_ReturnType, _Function>(_Func);
3831  }
template<typename _ReturnType>
template<typename _Ty >
void Concurrency::task< _ReturnType >::_TaskInitMaybeFunctor ( _Ty &  _Param,
std::false_type   
)
inlineprivate

Initializes a task using a non-callable object.

3838  {
3839  _TaskInitNoFunctor(_Param);
3840  }
void _TaskInitNoFunctor(task_completion_event< _ReturnType > &_Event)
Initializes a task using a task completion event.
Definition: ppltasks.h:3789
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_TaskInitNoFunctor ( task_completion_event< _ReturnType > &  _Event)
inlineprivate

Initializes a task using a task completion event.

3790  {
3791  _Event._RegisterTask(_M_Impl);
3792  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
template<typename _InternalReturnType , typename _Function >
void Concurrency::task< _ReturnType >::_TaskInitWithFunctor ( const _Function &  _Func)
inlineprivate

Initializes a task using a lambda, function pointer or function object.

3777  {
3778  typedef typename details::_InitFunctorTypeTraits<_InternalReturnType, std::result_of_t<_Function()>> _Async_type_traits;
3779 
3780  _M_Impl->_M_fFromAsync = _Async_type_traits::_IsAsyncTask;
3781  _M_Impl->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3782  _M_Impl->_M_taskEventLogger._LogScheduleTask(false);
3783  _M_Impl->_ScheduleTask(new _InitialTaskHandle<_InternalReturnType, _Function, typename _Async_type_traits::_AsyncKind>(_GetImpl(), _Func), details::_NoInline);
3784  }
Definition: pplinterface.h:224
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3371
template<typename _ReturnType>
template<typename _Function >
auto Concurrency::task< _ReturnType >::_Then ( const _Function &  _Func,
details::_CancellationTokenState _PTokenState,
details::_TaskInliningMode_t  _InliningMode = details::_ForceInline 
) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
inline

An internal version of then that takes additional flags and always execute the continuation inline by default. When _ForceInline is set to false, continuations inlining will be limited to default _DefaultAutoInline. This function is Used for runtime internal continuations only.

3428  {
3429  // inherit from antecedent
3430  auto _Scheduler = _GetImpl()->_GetScheduler();
3431 
3432  // Note: _ThenImpl's implementation makes a copy of the continuation_context when it schedules the continuation. '
3433  // The Continuation Context used to create the _ThenImplOptions must still exist when _ThenImpl executes.
3434  auto _Default_Context = task_continuation_context::use_default();
3435  details::_ThenImplOptions _Options (_PTokenState, &_Default_Context, _Scheduler, _CAPTURE_CALLSTACK(), _InliningMode);
3436 
3437 #ifndef _PPLTASKS_NO_STDFUNC
3438  return _ThenImpl<_ReturnType>(typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_StdFuncT(_Func), _Options);
3439 #else
3440  return _ThenImpl<_ReturnType>(_Func, _Options);
3441 #endif
3442  }
auto _Options
Definition: ppltasks.h:3180
#define _CAPTURE_CALLSTACK()
Helper macro to determine how many stack frames need to be saved. When any number less or equal to 1 ...
Definition: ppltasks.h:118
static task_continuation_context use_default()
Creates the default task continuation context.
Definition: ppltasks.h:937
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3371
std::function< _RetTypeT __cdecl(_ArgTypeT)> _StdFuncT
Definition: ppltasks.h:407
template<typename _ReturnType>
const details::_Task_ptr<_ReturnType>::_Type& Concurrency::task< _ReturnType >::_ThenGetImpl ( ) const
inline
3377  {
3378  if (!_M_Impl)
3379  {
3380  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3381  }
3382 
3383  return _M_Impl;
3384  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
return Concurrency::task< _ReturnType >::_ThenImpl ( typename details::_ContinuationTypeTraits< _Function, _ReturnType >::  _StdFuncT_Func,
_Options   
)
template<typename _ReturnType>
return Concurrency::task< _ReturnType >::_ThenImpl ( typename details::_ContinuationTypeTraits< _Function, _ReturnType >::  _StdFuncT_Func,
_Options   
)
template<typename _ReturnType>
template<typename _InternalReturnType , typename _Function >
auto Concurrency::task< _ReturnType >::_ThenImpl ( const _Function &  _Func,
details::_ThenImplOptions _Options 
) const -> typename details::_ContinuationTypeTraits<_Function, _InternalReturnType>::_TaskOfType
inlineprivate

The one and only implementation of then for void and non-void tasks.

3847  {
3848 
3849  typedef details::_FunctionTypeTraits<_Function, _InternalReturnType> _Function_type_traits;
3850  typedef details::_TaskTypeTraits<typename _Function_type_traits::_FuncRetType> _Async_type_traits;
3851  typedef typename _Async_type_traits::_TaskRetType _TaskType;
3852 
3853  //
3854  // A **nullptr** token state indicates that it was not provided by the user. In this case, we inherit the antecedent's token UNLESS this is a
3855  // an exception handling continuation. In that case, we break the chain with a _None. That continuation is never canceled unless the user
3856  // explicitly passes the same token.
3857  //
3858  if (_Options._PTokenState == nullptr)
3859  {
3860  if (_Function_type_traits::_Takes_task::value)
3861  {
3863  }
3864  else
3865  {
3866  _Options._PTokenState = _GetImpl()->_M_pTokenState;
3867  }
3868  }
3869 
3870  task<_TaskType> _ContinuationTask;
3871  _ContinuationTask._CreateImpl(_Options._PTokenState, _Options._Scheduler);
3872 
3873  _ContinuationTask._GetImpl()->_M_fFromAsync = (_GetImpl()->_M_fFromAsync || _Async_type_traits::_IsAsyncTask);
3874  _ContinuationTask._GetImpl()->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3875  _ContinuationTask._SetTaskCreationCallstack(_Options._CreationStack);
3876 
3877  _GetImpl()->_ScheduleContinuation(new _ContinuationTaskHandle<_InternalReturnType, _TaskType, _Function, typename _Function_type_traits::_Takes_task, typename _Async_type_traits::_AsyncKind>(
3878  _GetImpl(), _ContinuationTask._GetImpl(), _Func, *_Options._PContinuationContext, _Options._InliningMode));
3879 
3880  return _ContinuationTask;
3881  }
auto _Options
Definition: ppltasks.h:3180
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:332
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3371
template<typename _ReturnType>
Concurrency::task< _ReturnType >::details::_get_internal_task_options ( _TaskOptions  )
template<typename _ReturnType>
_ReturnType Concurrency::task< _ReturnType >::get ( ) const
inline

Returns the result this task produced. If the task is not in a terminal state, a call to get will wait for the task to finish. This method does not return a value when called on a task with a result_type of void.

Returns
The result of the task.

If the task is canceled, a call to get will throw a task_canceled exception. If the task encountered an different exception or an exception was propagated to it from an antecedent task, a call to get will throw that exception.

3266  {
3267  if (!_M_Impl)
3268  {
3269  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3270  }
3271 
3272  if (_M_Impl->_Wait() == canceled)
3273  {
3274  _THROW_NCEE(task_canceled, _EMPTY_ARGUMENT);
3275  }
3276 
3277  return _M_Impl->_GetResult();
3278  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
#define _THROW_NCEE(x, y)
Definition: xstddef:51
The task_group or structured_task_group object was canceled. One or more tasks may not have executed...
Definition: pplinterface.h:121
#define _EMPTY_ARGUMENT
Definition: xstddef:77
template<typename _ReturnType>
bool Concurrency::task< _ReturnType >::is_apartment_aware ( ) const
inline

Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such a task.

Returns
true if the task unwraps an IAsyncInfo interface or is descended from such a task, false otherwise.
3323  {
3324  if (!_M_Impl)
3325  {
3326  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3327  }
3328  return _M_Impl->_IsApartmentAware();
3329  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
bool Concurrency::task< _ReturnType >::is_done ( ) const
inline

Determines if the task is completed.

Returns
True if the task has completed, false otherwise.

The function returns true if the task is completed or canceled (with or without user exception).

3290  {
3291  if (!_M_Impl)
3292  {
3293  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3294  }
3295 
3296  return _M_Impl->_IsDone();
3297  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
bool Concurrency::task< _ReturnType >::operator!= ( const task< _ReturnType > &  _Rhs) const
inline

Determines whether two task objects represent different internal tasks.

Returns
true if the objects refer to different underlying tasks, and false otherwise.
3351  {
3352  return !operator==(_Rhs);
3353  }
bool operator==(const task< _ReturnType > &_Rhs) const
Determines whether two task objects represent the same internal task.
Definition: ppltasks.h:3338
template<typename _ReturnType>
task& Concurrency::task< _ReturnType >::operator= ( const task< _ReturnType > &  _Other)
inline

Replaces the contents of one task object with another.

Parameters
_OtherThe source task object.

As task behaves like a smart pointer, after a copy assignment, this task objects represents the same actual task as _Other does.

3080  {
3081  if (this != &_Other)
3082  {
3083  _M_Impl = _Other._M_Impl;
3084  }
3085  return *this;
3086  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
task& Concurrency::task< _ReturnType >::operator= ( task< _ReturnType > &&  _Other)
inline

Replaces the contents of one task object with another.

Parameters
_OtherThe source task object.

As task behaves like a smart pointer, after a copy assignment, this task objects represents the same actual task as _Other does.

3100  {
3101  if (this != &_Other)
3102  {
3103  _M_Impl = std::move(_Other._M_Impl);
3104  }
3105  return *this;
3106  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1349
template<typename _ReturnType>
bool Concurrency::task< _ReturnType >::operator== ( const task< _ReturnType > &  _Rhs) const
inline

Determines whether two task objects represent the same internal task.

Returns
true if the objects refer to the same underlying task, and false otherwise.
3339  {
3340  return (_M_Impl == _Rhs._M_Impl);
3341  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
scheduler_ptr Concurrency::task< _ReturnType >::scheduler ( ) const
inline

Returns the scheduler for this task

Returns
A pointer to the scheduler
3306  {
3307  if (!_M_Impl)
3308  {
3309  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3310  }
3311 
3312  return _M_Impl->_GetScheduler();
3313  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
template<typename _ReturnType>
task_status Concurrency::task< _ReturnType >::wait ( ) const
inline

Waits for this task to reach a terminal state. It is possible for wait to execute the task inline, if all of the tasks dependencies are satisfied, and it has not already been picked up for execution by a background worker.

Returns
A task_status value which could be either completed or canceled. If the task encountered an exception during execution, or an exception was propagated to it from an antecedent task, wait will throw that exception.
3244  {
3245  if (!_M_Impl)
3246  {
3247  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3248  }
3249 
3250  return _M_Impl->_Wait();
3251  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884

Friends And Related Function Documentation

template<typename _ReturnType>
template<typename _Ty >
friend class task
friend

Member Data Documentation

template<typename _ReturnType>
cancellation_token Concurrency::task< _ReturnType >::_CancellationToken
template<typename _ReturnType>
auto Concurrency::task< _ReturnType >::_ContinuationContext = _TaskOptions.get_continuation_context()
template<typename _ReturnType>
details::_Task_ptr<_ReturnType>::_Type Concurrency::task< _ReturnType >::_M_Impl
private
template<typename _ReturnType>
auto Concurrency::task< _ReturnType >::_Options = details::_ThenImplOptions::_CreateOptions(_TaskOptions, _ContinuationContext, _ThenGetImpl()->_GetScheduler())
template<typename _ReturnType>
const task_options& Concurrency::task< _ReturnType >::_TaskOptions
Initial value:
{
details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param)

The documentation for this class was generated from the following file: