5#include <system/object.h>
6#include <system/func.h>
7#include <system/threading/tasks/task.h>
9namespace System {
namespace Runtime {
namespace CompilerServices {
11class ResultTaskAwaiter;
13class ConfiguredResultTaskAwaitable;
16namespace Threading {
namespace Tasks {
63 auto result = MakeObject<Task>(
64 std::function<
void()>([continuationAction, task =
MakeSharedPtr(
this)] { continuationAction(task); }));
74 template<
typename TNewResult>
77 auto result = MakeObject<ResultTask<TNewResult>>(std::function<TNewResult()>(
78 [continuationFunction, task =
MakeSharedPtr(
this)] {
return continuationFunction(task); }));
133namespace Runtime {
namespace CompilerServices {
144 return m_task->get_IsCompleted();
149 m_task->AddCompletionAction(continuation);
154 return m_task->get_Result();
168 : m_task(task), m_continueOnCapturedContext(continueOnCapturedContext)
173 auto result = m_task->GetAwaiter();
174 result.continueOnCapturedContext = m_continueOnCapturedContext;
180 bool m_continueOnCapturedContext;
Function delegate. This type should be allocated on stack and passed to functions by value or by refe...
Definition: func.h:82
Definition: result_task.h:137
T GetResult() const
Definition: result_task.h:152
ResultTaskAwaiter(const RTaskPtr< T > &task)
Definition: result_task.h:139
void OnCompleted(const Action<> &continuation)
Definition: result_task.h:147
bool continueOnCapturedContext
Definition: result_task.h:157
bool get_IsCompleted() const
Definition: result_task.h:142
A Task specialization that returns a result value upon completion.
Definition: result_task.h:24
Runtime::CompilerServices::ConfiguredResultTaskAwaitable< T > ConfigureAwait(bool continueOnCapturedContext) const
Configures how awaits on this result task should behave regarding context capture.
Definition: result_task.h:50
void Complete(const T &result)
Sets the result value for the task and completes it.
Definition: result_task.h:111
T get_Result()
Gets the result of the asynchronous operation.
Definition: result_task.h:40
TaskPtr ContinueWith(const Action< RTaskPtr< T > > &continuationAction)
Creates a continuation that executes when the result task completes.
Definition: result_task.h:61
ResultTask(const Func< T > &function)
Constructs a ResultTask with a function that returns a value.
Definition: result_task.h:31
ResultTask(const T &result)
Internal constructor for creating result tasks with specified result.
Definition: result_task.h:99
ResultTask()
Internal implementation. Not for user code.
Definition: result_task.h:94
void set_Result(const T &result)
Sets the result value for the task.
Definition: result_task.h:105
Runtime::CompilerServices::ResultTaskAwaiter< T > GetAwaiter() const
Gets an awaiter for this result task for use with Await.
Definition: result_task.h:86
RTaskPtr< TNewResult > ContinueWith(const Func< RTaskPtr< T >, TNewResult > &continuationFunction)
Creates a continuation that executes when the result task completes.
Definition: result_task.h:75
Represents an asynchronous operation that can be awaited and composed with other tasks.
Definition: task.h:30
void Wait()
Waits for the task to complete.
Task()
Internal constructor for creating uninitialized tasks.
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.
void ContinueWithCore(const TaskPtr &continuationTask)
Internal implementation for adding continuations.
std::function< void()> FunctionT
Internal implementation. Not for user code.
Definition: task.h:126
void set_Status(TaskStatus status)
Sets the task status.
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