7#include <system/idisposable.h>
8#include <system/threading/tasks/task_status.h>
9#include <system/threading/cancellation_token.h>
10#include <system/action.h>
11#include <system/aggregate_exception.h>
16namespace Threading {
namespace Tasks {
19namespace Runtime {
namespace CompilerServices {
21class ConfiguredTaskAwaitable;
24namespace Threading {
namespace Tasks {
70 int32_t
get_Id()
const {
return m_id;}
86 template<
typename TResult>
118 ASPOSECPP_SHARED_API
void Wait();
157 ASPOSECPP_SHARED_API
virtual void Finish();
185namespace Runtime {
namespace CompilerServices {
196 bool continueOnCapturedContext =
false;
210 bool m_continueOnCapturedContext;
215#include <system/func.h>
216#include <system/threading/tasks/result_task.h>
218namespace System {
namespace Threading {
namespace Tasks {
220template <
typename TResult>
223 auto result = MakeObject<Threading::Tasks::ResultTask<TResult>>(
Template that represents wrapper of exceptions that are derived from Exception class.
Definition: exception.h:113
Function delegate. This type should be allocated on stack and passed to functions by value or by refe...
Definition: func.h:82
Defines method that releases resources owned by the current object. Objects of this class should only...
Definition: idisposable.h:30
Forward declaration.
Definition: nullable.h:75
void OnCompleted(const Action<> &continuation)
TaskAwaiter(const TaskPtr &task)
Definition: task.h:190
bool get_IsCompleted() const
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Propagates notification that operations should be canceled. This class provides a mechanism for coope...
Definition: cancellation_token.h:43
Represents an asynchronous operation that can be awaited and composed with other tasks.
Definition: task.h:30
bool get_IsFaulted() const
Gets whether the task completed due to an unhandled exception.
Definition: task.h:76
static std::atomic< int32_t > m_next_id
ID of next task will be created.
Definition: task.h:180
void set_Function(const FunctionT &fnc)
Sets the internal function to execute.
Definition: task.h:131
bool get_IsCanceled() const
Gets whether the task completed due to cancellation.
Definition: task.h:63
void Cancel()
Marks the task as cancelled and finishes task.
std::exception_ptr m_exception
Captured exception if the task faulted.
Definition: task.h:167
AggregateException get_Exception() const
Gets the ID for task.
void Start()
Starts the task execution using the default scheduler.
int32_t get_Id() const
Definition: task.h:70
void Wait()
Waits for the task to complete.
SharedPtr< Object > m_state
User-defined state object.
Definition: task.h:173
void AddCompletionAction(const Action<> &continuation)
Adds a continuation action to be executed upon completion.
void Dispose() override
Releases resources associated with the task.
Runtime::CompilerServices::TaskAwaiter GetAwaiter() const
Gets an awaiter for this task for use with Await.
void set_Scheduler(const SharedPtr< TaskScheduler > &scheduler)
Sets the scheduler associated with this task.
Definition: task.h:137
FunctionT m_function
The function to execute.
Definition: task.h:163
void RunSynchronously()
Runs the task synchronously on the current thread.
void Activate(const SharedPtr< TaskScheduler > &scheduler=nullptr)
Activates the task for execution on a scheduler.
Task()
Internal constructor for creating uninitialized tasks.
void Execute()
Executes the task's function.
Runtime::CompilerServices::ConfiguredTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) const
Configures how awaits on this task should behave regarding context capture.
Task(const Action< SharedPtr< Object > > &action, const SharedPtr< Object > &state, const CancellationToken &cancellationToken)
Constructs a Task with stateful action, state, and cancellation token.
void Wait(const CancellationToken &cancellationToken)
Waits for the task to complete with cancellation support.
TaskStatus get_Status() const
Gets the current status of the task.
Definition: task.h:66
SharedPtr< TaskScheduler > m_scheduler
Scheduler responsible for executing the task.
Definition: task.h:171
void Complete()
Marks the task as completed and finishes task.
TaskPtr ContinueWith(const Action< TaskPtr > &continuationAction)
Creates a continuation that executes when the task completes.
int32_t m_id
Definition: task.h:161
bool get_IsCompleted() const
Gets whether the task has completed.
Task(const Action<> &action)
Constructs a Task with an action to execute.
void ExecuteContinuations()
Executes all registered continuations.
CancellationToken m_cancellation_token
Cancellation token for the task.
Definition: task.h:169
static Nullable< int32_t > get_CurrentId()
static const TaskPtr & get_CompletedTask()
Gets a completed task (singleton)
Task(const Action<> &action, const CancellationToken &cancellationToken)
Constructs a Task with an action and cancellation token.
std::list< Action<> > m_completions
List of continuation tasks to execute after completion.
Definition: task.h:175
Task(const Action< SharedPtr< Object > > &action, const SharedPtr< Object > &state)
Constructs a Task with a stateful action and state object.
void ContinueWithCore(const TaskPtr &continuationTask)
Internal implementation for adding continuations.
const SharedPtr< Object > & get_AsyncState() const
Gets the user-defined state object associated with the task.
Definition: task.h:73
std::mutex m_completions_mutex
Mutex protecting continuations operations.
Definition: task.h:177
void Start(const SharedPtr< TaskScheduler > &scheduler)
Starts the task execution using the specified scheduler.
TaskStatus m_status
Current execution status.
Definition: task.h:165
virtual void Finish()
Finalizes task completion and executes continuations.
std::function< void()> FunctionT
Internal implementation. Not for user code.
Definition: task.h:126
const SharedPtr< TaskScheduler > & get_Scheduler() const
Gets the scheduler associated with this task.
Definition: task.h:135
void RunSynchronously(const SharedPtr< TaskScheduler > &scheduler)
Runs the task synchronously using the specified scheduler.
void set_Status(TaskStatus status)
Sets the task status.
TaskStatus
Definition: task_status.h:8
Definition: db_command.h:9
MulticastDelegate< void(Args...)> Action
Delegate type that references methods that have no return value.
Definition: action.h:40
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1650