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>
15namespace Threading {
namespace Tasks {
18namespace Runtime {
namespace CompilerServices {
20class ConfiguredTaskAwaitable;
23namespace Threading {
namespace Tasks {
68 int32_t
get_Id()
const {
return m_id;}
112 ASPOSECPP_SHARED_API
void Wait()
const;
159 std::exception_ptr m_exception;
167 std::list<Action<>> m_continuations;
169 std::mutex m_continuations_mutex;
172 static std::atomic<int32_t> m_next_id;
177namespace Runtime {
namespace CompilerServices {
188 bool continueOnCapturedContext =
false;
202 bool m_continueOnCapturedContext;
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:182
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:29
bool get_IsFaulted() const
Gets whether the task completed due to an unhandled exception.
Definition: task.h:74
void AddContinuation(const Action<> &continuation)
Adds a continuation action to be executed upon completion.
void set_Function(const FunctionT &fnc)
Sets the internal function to execute.
Definition: task.h:125
bool get_IsCanceled() const
Gets whether the task completed due to cancellation.
Definition: task.h:62
void Start()
Starts the task execution using the default scheduler.
int32_t get_Id() const
Gets the ID for task.
Definition: task.h:68
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 RunSynchronously()
Runs the task synchronously on the current thread.
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.
TaskStatus get_Status() const
Gets the current status of the task.
Definition: task.h:65
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.
bool get_IsCompleted() const
Gets whether the task has completed.
TaskScheduler * get_Scheduler() const
Gets the scheduler associated with this task.
Definition: task.h:129
Task(const Action<> &action)
Constructs a Task with an action to execute.
void ExecuteContinuations()
Executes all registered continuations.
void Activate(TaskScheduler *=nullptr)
Activates the task for execution on a scheduler.
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.
Task(const Action< SharedPtr< Object > > &action, const SharedPtr< Object > &state)
Constructs a Task with a stateful action and state object.
void Wait() const
Waits for the task to complete.
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:71
void Start(const SharedPtr< TaskScheduler > &scheduler)
Starts the task execution using the specified scheduler.
void set_Scheduler(TaskScheduler *scheduler)
Sets the scheduler associated with this task.
Definition: task.h:131
std::function< void()> FunctionT
Internal implementation. Not for user code.
Definition: task.h:120
void RunSynchronously(const SharedPtr< TaskScheduler > &scheduler)
Runs the task synchronously using the specified scheduler.
void Finish()
Finalizes task completion and executes continuations.
void set_Status(TaskStatus status)
Sets the task status.
void Wait(const CancellationToken &cancellationToken) const
Waits for the task to complete with cancellation support.
Represents an object that handles the low-level work of queuing tasks onto threads.
Definition: task_scheduler.h:12
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