20 class task<void> :
public xtd::threading::tasks::basic_task<> {
25 std::coroutine_handle<promise_type> this_;
27 auto final_suspend()
noexcept {
28 struct final_awaiter {
31 bool await_ready()
noexcept {
return false;}
32 void await_resume()
noexcept {}
33 void await_suspend(std::coroutine_handle<promise_type> handle)
noexcept {
34 if (!promise.task_->is_completed()) promise.task_->start();
35 promise.this_.destroy();
38 return final_awaiter {*
this};
42 this_ = std::coroutine_handle<promise_type>::from_promise(*
this);
45 std::suspend_never initial_suspend() {
return {};}
47 void unhandled_exception() {exception_ = task_->xtd::threading::tasks::basic_task<>::data_->exception;}
53 bool await_ready()
const noexcept {
return task_.is_completed();}
55 task_.on_await_resume();
56 if (task_.is_faulted()) task_.rethrow_exception();
58 void await_suspend(std::coroutine_handle<> handle) {task_.continue_with_([handle] {handle.resume();});}
77 [[nodiscard]]
static auto from_result() -> task {
80 t.basic_task<>::data_->end_event.set();
88 auto operator co_await()
noexcept {
return awaiter {*
this};}
93 inline task<void>::task() {
94 lock_(this->static_data_.sync_root) {
95 this->static_data_.tasks.add(this->data_->unique_id,
new_sptr<
task<>>(*
this));
98 inline task<void>::task(
auto action) : basic_task<> {action} {
99 lock_(this->static_data_.sync_root) {
100 this->static_data_.tasks.add(this->data_->unique_id,
new_sptr<task<>>(*
this));
103 inline task<void>::task(
auto action,
const xtd::threading::cancellation_token& cancellation_token) : basic_task<> {action, cancellation_token} {
104 lock_(this->static_data_.sync_root) {
105 this->static_data_.tasks.add(this->data_->unique_id,
new_sptr<task<>>(*
this));
108 inline task<void>::task(
auto action,
const xtd::any_object& state) : basic_task<> {action, state} {
109 lock_(this->static_data_.sync_root) {
110 this->static_data_.tasks.add(this->data_->unique_id,
new_sptr<task<>>(*
this));
113 inline task<void>::task(
auto action,
const xtd::any_object& state,
const xtd::threading::cancellation_token& cancellation_token) : basic_task<> {action, state, cancellation_token} {
114 lock_(this->static_data_.sync_root) {
115 this->static_data_.tasks.add(this->data_->unique_id,
new_sptr<task<>>(*
this));
Contains xtd::threading::tasks::basic_task <> class.
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:30
Represents an exception whose state is captured at a certain point in code.
Definition exception_dispatch_info.hpp:30
Propagates notification that operations should be canceled.
Definition cancellation_token.hpp:39
Represents an asynchronous operation.
Definition task_result.hpp:20
#define lock_(object)
The lock_ keyword marks a statement block as a critical section by obtaining the mutual-exclusion loc...
Definition lock.hpp:68
@ ran_to_completion
The task completed execution successfully.
Definition task_status.hpp:35
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
auto new_ptr(args_t &&... args) -> xtd::ptr< type_t >
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
auto new_sptr(args_t &&... args) -> xtd::sptr< type_t >
xtd::new_sptr operator creates a xtd::sptr object.
Definition new_sptr.hpp:24
@ t
The T key.
Definition console_key.hpp:126
The xtd::threading::tasks namespace provides types that simplify the work of writing concurrent and a...
Definition itask.hpp:14
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::threading::tasks::task <result_t> class.