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, 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 (_Func, _TaskOptions)
 
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 (_Func, _TaskOptions)
 
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...
 
void _SetImpl (const typename details::_Task_ptr< _ReturnType >::_Type &_Impl)
 Set the implementation of the task to be the supplied implementaion. More...
 
void _SetImpl (typename details::_Task_ptr< _ReturnType >::_Type &&_Impl)
 Set the implementation of the task to be the supplied implementaion 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
 
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, const task_options &_TaskOptions) const -> typename details::_ContinuationTypeTraits< _Function, _InternalReturnType >::_TaskOfType
 
template<typename _InternalReturnType , typename _Function >
auto _ThenImpl (const _Function &_Func, details::_CancellationTokenState *_PTokenState, const task_continuation_context &_ContinuationContext, scheduler_ptr _Scheduler, details::_TaskCreationCallstack _CreationStack, details::_TaskInliningMode_t _InliningMode=details::_NoInline) 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 T >
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 lamda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lamda 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).

3158  : _M_Impl(nullptr)
3159  {
3160  // The default constructor should create a task with a nullptr impl. This is a signal that the
3161  // task is not usable and should throw if any wait(), get() or then() APIs are used.
3162  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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 lamda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lamda 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).

3285 : _M_Impl(_Other._M_Impl) {}
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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 lamda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lamda 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).

3312 : _M_Impl(std::move(_Other._M_Impl)) {}
_OutIt move(_InIt _First, _InIt _Last, _OutIt _Dest)
Definition: xutility:2447
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105

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 lamda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lamda 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).

3202  {
3203  task_options _TaskOptions;
3204  details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param);
3205 
3206  _CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler());
3207  // Do not move the next line out of this function. It is important that _CAPTURE_CALLSTACK() evaluate to the the call site of the task constructor.
3209 
3210  _TaskInitMaybeFunctor(_Param, details::_IsCallable(_Param,0));
3211  }
const task_options & _TaskOptions
Definition: ppltasks.h:3250
auto _IsCallable(_Function _Func, int) -> decltype(_Func(), std::true_type())
Definition: ppltasks.h:395
_SetTaskCreationCallstack(details::_get_internal_task_options(_TaskOptions)._M_hasPresetCreationCallstack?details::_get_internal_task_options(_TaskOptions)._M_presetCreationCallstack:_CAPTURE_CALLSTACK())
_TaskInitMaybeFunctor(_Param, details::_IsCallable(_Param, 0))
#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:162
_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 lamda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lamda 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).

3377  {
3378  task_options _TaskOptions;
3380  return _ThenImpl<_ReturnType, _Function>(_Func, _TaskOptions);
3381  }
void _set_creation_callstack(const _TaskCreationCallstack &_callstack)
Definition: ppltasks.h:1178
const task_options & _TaskOptions
Definition: ppltasks.h:3250
_Internal_task_options & _get_internal_task_options(task_options &options)
Definition: ppltasks.h:1370
#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:162
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.

3577  {
3578  _ASSERTE(_Ct != nullptr);
3581  {
3582  _M_Impl->_RegisterCancellation(_M_Impl);
3583  }
3584  }
#define _ASSERTE(expr)
Definition: crtdbg.h:216
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:328
static _Type _Make(_CancellationTokenState *_Ct, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:1386
template<typename _ReturnType>
const details::_Task_ptr<_ReturnType>::_Type& Concurrency::task< _ReturnType >::_GetImpl ( ) const
inline

Return the underlying implementation for this task.

3590  {
3591  return _M_Impl;
3592  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_SetAsync ( bool  _Async = true)
inline

Sets a property determining whether the task is apartment aware.

3616  {
3617  _GetImpl()->_SetAsync(_Async);
3618  }
future< typename result_of< _Fty(_ArgTypes...)>::type > _Async(_Launch_type _Policy, _Fty &&_Fnarg, _ArgTypes &&..._Args)
Definition: future:1874
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3589
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 implementaion.

3598  {
3599  _ASSERTE(!_M_Impl);
3600  _M_Impl = _Impl;
3601  }
#define _ASSERTE(expr)
Definition: crtdbg.h:216
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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 implementaion using a move instead of a copy.

3607  {
3608  _ASSERTE(!_M_Impl);
3609  _M_Impl = std::move(_Impl);
3610  }
_OutIt move(_InIt _First, _InIt _Last, _OutIt _Dest)
Definition: xutility:2447
#define _ASSERTE(expr)
Definition: crtdbg.h:216
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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.

3624  {
3625  _GetImpl()->_SetTaskCreationCallstack(_callstack);
3626  }
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3589
template<typename _ReturnType>
Concurrency::task< _ReturnType >::_TaskInitMaybeFunctor ( _Param  ,
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.

4031  {
4032  _TaskInitWithFunctor<_ReturnType, _Function>(_Func);
4033  }
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.

4040  {
4041  _TaskInitNoFunctor(_Param);
4042  }
void _TaskInitNoFunctor(task_completion_event< _ReturnType > &_Event)
Initializes a task using a task completion event.
Definition: ppltasks.h:3988
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_TaskInitNoFunctor ( task_completion_event< _ReturnType > &  _Event)
inlineprivate

Initializes a task using a task completion event.

3989  {
3990  _Event._RegisterTask(_M_Impl);
3991  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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.

3976  {
3977  typedef typename details::_InitFunctorTypeTraits<_InternalReturnType, decltype(_Func())> _Async_type_traits;
3978 
3979  _M_Impl->_M_fFromAsync = _Async_type_traits::_IsAsyncTask;
3980  _M_Impl->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3981  _M_Impl->_M_taskEventLogger._LogScheduleTask(false);
3982  _M_Impl->_ScheduleTask(new _InitialTaskHandle<_InternalReturnType, _Function, typename _Async_type_traits::_AsyncKind>(_GetImpl(), _Func), details::_NoInline);
3983  }
Definition: concrt.h:5273
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3589
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.

3636  {
3637  // inherit from antecedent
3638  auto _Scheduler = _GetImpl()->_GetScheduler();
3639 
3640  return _ThenImpl<_ReturnType, _Function>(_Func, _PTokenState, task_continuation_context::use_default(), _Scheduler, _CAPTURE_CALLSTACK(), _InliningMode);
3641  }
#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:162
static task_continuation_context use_default()
Creates the default task continuation context.
Definition: ppltasks.h:1109
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3589
template<typename _ReturnType>
return Concurrency::task< _ReturnType >::_ThenImpl ( _Func  ,
_TaskOptions   
)
template<typename _ReturnType>
return Concurrency::task< _ReturnType >::_ThenImpl ( _Func  ,
_TaskOptions   
)
template<typename _ReturnType>
template<typename _InternalReturnType , typename _Function >
auto Concurrency::task< _ReturnType >::_ThenImpl ( const _Function &  _Func,
const task_options _TaskOptions 
) const -> typename details::_ContinuationTypeTraits<_Function, _InternalReturnType>::_TaskOfType
inlineprivate
4046  {
4047  if (!_M_Impl)
4048  {
4049  throw invalid_operation("then() cannot be called on a default constructed task.");
4050  }
4051 
4052  details::_CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() : nullptr;
4053  auto _Scheduler = _TaskOptions.has_scheduler() ? _TaskOptions.get_scheduler() : _GetImpl()->_GetScheduler();
4055  return _ThenImpl<_InternalReturnType, _Function>(_Func, _PTokenState, _TaskOptions.get_continuation_context(), _Scheduler, _CreationStack);
4056  }
_TaskCreationCallstack _M_presetCreationCallstack
Definition: ppltasks.h:1176
const task_options & _TaskOptions
Definition: ppltasks.h:3250
_Internal_task_options & _get_internal_task_options(task_options &options)
Definition: ppltasks.h:1370
cancellation_token get_cancellation_token() const
Returns the cancellation token
Definition: ppltasks.h:1325
bool has_scheduler() const
Indicates whether a scheduler n was specified by the user
Definition: ppltasks.h:1341
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
bool has_cancellation_token() const
Indicates whether a cancellation token was specified by the user
Definition: ppltasks.h:1317
task_continuation_context get_continuation_context() const
Returns the continuation context
Definition: ppltasks.h:1333
bool _M_hasPresetCreationCallstack
Definition: ppltasks.h:1175
_ImplType _GetImplValue() const
Definition: pplcancellation_token.h:748
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3589
scheduler_ptr get_scheduler() const
Returns the scheduler
Definition: ppltasks.h:1349
template<typename _ReturnType>
template<typename _InternalReturnType , typename _Function >
auto Concurrency::task< _ReturnType >::_ThenImpl ( const _Function &  _Func,
details::_CancellationTokenState _PTokenState,
const task_continuation_context _ContinuationContext,
scheduler_ptr  _Scheduler,
details::_TaskCreationCallstack  _CreationStack,
details::_TaskInliningMode_t  _InliningMode = details::_NoInline 
) const -> typename details::_ContinuationTypeTraits<_Function, _InternalReturnType>::_TaskOfType
inlineprivate

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

4064  {
4065  if (!_M_Impl)
4066  {
4067  throw invalid_operation("then() cannot be called on a default constructed task.");
4068  }
4069 
4070  typedef details::_FunctionTypeTraits<_Function, _InternalReturnType> _Function_type_traits;
4071  typedef details::_TaskTypeTraits<typename _Function_type_traits::_FuncRetType> _Async_type_traits;
4072  typedef typename _Async_type_traits::_TaskRetType _TaskType;
4073 
4074  //
4075  // 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
4076  // an exception handling continuation. In that case, we break the chain with a _None. That continuation is never canceled unless the user
4077  // explicitly passes the same token.
4078  //
4079  if (_PTokenState == nullptr)
4080  {
4081  if (_Function_type_traits::_Takes_task::value)
4082  {
4083  _PTokenState = details::_CancellationTokenState::_None();
4084  }
4085  else
4086  {
4087  _PTokenState = _GetImpl()->_M_pTokenState;
4088  }
4089  }
4090 
4091  task<_TaskType> _ContinuationTask;
4092  _ContinuationTask._CreateImpl(_PTokenState, _Scheduler);
4093 
4094  _ContinuationTask._GetImpl()->_M_fFromAsync = (_GetImpl()->_M_fFromAsync || _Async_type_traits::_IsAsyncTask);
4095  _ContinuationTask._GetImpl()->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
4096  _ContinuationTask._SetTaskCreationCallstack(_CreationStack);
4097 
4098  _GetImpl()->_ScheduleContinuation(new _ContinuationTaskHandle<_InternalReturnType, _TaskType, _Function, typename _Function_type_traits::_Takes_task, typename _Async_type_traits::_AsyncKind>(
4099  _GetImpl(), _ContinuationTask._GetImpl(), _Func, _ContinuationContext, _InliningMode));
4100 
4101  return _ContinuationTask;
4102  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:328
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3589
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.

3484  {
3485  if (!_M_Impl)
3486  {
3487  throw invalid_operation("get() cannot be called on a default constructed task.");
3488  }
3489 
3490  if (_M_Impl->_Wait() == canceled)
3491  {
3492  throw task_canceled();
3493  }
3494 
3495  return _M_Impl->_GetResult();
3496  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
The task_group or structured_task_group object was canceled. One or more tasks may not have executed...
Definition: pplinterface.h:133
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.
3541  {
3542  if (!_M_Impl)
3543  {
3544  throw invalid_operation("is_apartment_aware() cannot be called on a default constructed task.");
3545  }
3546  return _M_Impl->_IsApartmentAware();
3547  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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).

3508  {
3509  if (!_M_Impl)
3510  {
3511  throw invalid_operation("is_done() cannot be called on a default constructed task.");
3512  }
3513 
3514  return _M_Impl->_IsDone();
3515  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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.
3569  {
3570  return !operator==(_Rhs);
3571  }
bool operator==(const task< _ReturnType > &_Rhs) const
Determines whether two task objects represent the same internal task.
Definition: ppltasks.h:3556
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.

3326  {
3327  if (this != &_Other)
3328  {
3329  _M_Impl = _Other._M_Impl;
3330  }
3331  return *this;
3332  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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.

3346  {
3347  if (this != &_Other)
3348  {
3349  _M_Impl = std::move(_Other._M_Impl);
3350  }
3351  return *this;
3352  }
_OutIt move(_InIt _First, _InIt _Last, _OutIt _Dest)
Definition: xutility:2447
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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.
3557  {
3558  return (_M_Impl == _Rhs._M_Impl);
3559  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
template<typename _ReturnType>
scheduler_ptr Concurrency::task< _ReturnType >::scheduler ( ) const
inline

Returns the scheduler for this task

Returns
A pointer to the scheduler
3524  {
3525  if (!_M_Impl)
3526  {
3527  throw invalid_operation("scheduler() cannot be called on a default constructed task.");
3528  }
3529 
3530  return _M_Impl->_GetScheduler();
3531  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
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.
3462  {
3463  if (!_M_Impl)
3464  {
3465  throw invalid_operation("wait() cannot be called on a default constructed task.");
3466  }
3467 
3468  return _M_Impl->_Wait();
3469  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105

Friends And Related Function Documentation

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

Member Data Documentation

template<typename _ReturnType>
cancellation_token Concurrency::task< _ReturnType >::_CancellationToken
template<typename _ReturnType>
details::_Task_ptr<_ReturnType>::_Type Concurrency::task< _ReturnType >::_M_Impl
private
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: