36 template<
class result_t>
46 template<
class result_t>
56 template<
class result_t>
66 template<
class result_t>
86 auto start_new(
const std::function<
void(
const xtd::any_object&)>&
action,
const xtd::any_object& state)
const -> xtd::threading::tasks::task<> {
87 auto t = xtd::threading::tasks::task<> {
action, state};
91 auto start_new(
const std::function<
void(
const xtd::any_object&)>&
action,
const xtd::any_object& state,
const xtd::threading::cancellation_token& cancellation_token)
const -> xtd::threading::tasks::task<> {
92 auto t = xtd::threading::tasks::task<> {
action, state, cancellation_token};
97 template<
class result_t>
98 auto start_new(
const std::function<result_t()>&
action)
const -> xtd::threading::tasks::task<result_t> {
99 auto t = xtd::threading::tasks::task<result_t> {
action};
103 template<
class result_t>
104 auto start_new(
const std::function<result_t()>&
action,
const xtd::threading::cancellation_token& cancellation_token)
const -> xtd::threading::tasks::task<result_t> {
105 auto t = xtd::threading::tasks::task<result_t> {
action, cancellation_token};
109 template<
class result_t>
110 auto start_new(
const std::function<result_t(
const xtd::any_object&)>&
action,
const xtd::any_object& state)
const -> xtd::threading::tasks::task<result_t> {
111 auto t = xtd::threading::tasks::task<result_t> {
action, state};
115 template<
class result_t>
116 auto start_new(
const std::function<result_t(
const xtd::any_object&)>&
action,
const xtd::any_object& state,
const xtd::threading::cancellation_token& cancellation_token)
const -> xtd::threading::tasks::task<result_t> {
117 auto t = xtd::threading::tasks::task<result_t> {
action, state, cancellation_token};
125 template<
class result_t>
126 struct xtd::threading::tasks::basic_task<result_t>::yield_awaiter {
127 xtd::threading::tasks::task<result_t> task_;
129 yield_awaiter() {task_.start();};
130 bool await_ready() const noexcept {
return task_.is_completed();}
131 void await_resume() {
if (task_.is_faulted()) task_.rethrow_exception();}
132 void await_suspend(std::coroutine_handle<> handle) {task_.continue_with([handle] {
handle.resume();});}
135 template<
class result_t>
136 auto basic_task<result_t>::completed_task() -> xtd::threading::tasks::task<result_t> {
137 auto task = xtd::threading::tasks::task<result_t> {};
139 task.basic_task<result_t>::data_->end_event.set();
143 template<
class result_t>
144 auto basic_task<result_t>::factory() noexcept -> const xtd::threading::tasks::
task_factory& {
145 static auto factory = xtd::threading::tasks::task_factory {};
149 template<
class result_t>
150 auto basic_task<result_t>::delay(
const xtd::time_span& delay) -> xtd::threading::tasks::task<> {
return basic_task<result_t>::delay(
xtd::as<xtd::int32>(delay.total_milliseconds()));}
152 template<
class result_t>
153 auto basic_task<result_t>::delay(
const xtd::time_span& delay,
const xtd::threading::cancellation_token& cancellation_token) ->
task<> {
return basic_task<result_t>::delay(
xtd::as<xtd::int32>(delay.total_milliseconds()), cancellation_token);}
155 template<
class result_t>
156 auto basic_task<result_t>::delay(
xtd::int32 milliseconds_delay) -> xtd::threading::tasks::task<> {
return xtd::threading::tasks::task<>::run([milliseconds_delay]{xtd::threading::cancellation_token {}.wait_handle().wait_one(milliseconds_delay);});}
158 template<
class result_t>
159 auto basic_task<result_t>::delay(
xtd::int32 milliseconds_delay,
const xtd::threading::cancellation_token& cancellation_token) ->
task<> {
160 return xtd::threading::tasks::task<>::run([cancellation_token, milliseconds_delay]{xtd::threading::cancellation_token {cancellation_token}.wait_handle().wait_one(milliseconds_delay);}, cancellation_token);
163 template<
class result_t>
164 auto basic_task<result_t>::from_cancelation(
const xtd::threading::cancellation_token& cancellation_token) ->
task<result_t> {
166 auto task = xtd::threading::tasks::task<result_t> {};
167 task.basic_task<>::data_->cancellation_token = cancellation_token;
169 task.basic_task<>::data_->end_event.set();
173 template<
class result_t>
174 template<
class from_exception_t>
175 auto basic_task<result_t>::from_exception(from_exception_t exception) -> xtd::threading::tasks::task<result_t> {
176 auto task = xtd::threading::tasks::task<result_t> {};
179 task.basic_task<>::data_->end_event.set();
183 template<
class result_t>
184 auto xtd::threading::tasks::basic_task<result_t>::run(
const xtd::func<result_t>&
func) -> xtd::threading::tasks::task<result_t> {
return factory().start_new(
func);}
185 template<
class result_t>
186 auto xtd::threading::tasks::basic_task<result_t>::run(
const xtd::func<result_t>&
func,
const xtd::threading::cancellation_token& cancellation_token) -> xtd::threading::tasks::task<result_t> {
return factory().start_new(
func, cancellation_token);}
187 template<
class result_t>
189 template<
class result_t>
190 auto xtd::threading::tasks::basic_task<result_t>::run(
const xtd::func<result_t, const xtd::any_object&>&
func,
const xtd::any_object& state,
const xtd::threading::cancellation_token& cancellation_token) -> xtd::threading::tasks::task<result_t> {
return factory().start_new(
func, state, cancellation_token);}
191 template<
class result_t>
192 auto xtd::threading::tasks::basic_task<result_t>::run(
const std::function<result_t()>&
func) -> xtd::threading::tasks::task<result_t> {
return factory().start_new(
func);}
193 template<
class result_t>
194 auto xtd::threading::tasks::basic_task<result_t>::run(
const std::function<result_t()>&
func,
const xtd::threading::cancellation_token& cancellation_token) -> xtd::threading::tasks::task<result_t> {
return factory().start_new(
func, cancellation_token);}
195 template<
class result_t>
196 auto xtd::threading::tasks::basic_task<result_t>::run(
const std::function<result_t(
const xtd::any_object&)>&
func,
const xtd::any_object& state) -> xtd::threading::tasks::task<result_t> {
return factory().start_new(
func, state);}
197 template<
class result_t>
198 auto xtd::threading::tasks::basic_task<result_t>::run(
const std::function<result_t(
const xtd::any_object&)>&
func,
const xtd::any_object& state,
const xtd::threading::cancellation_token& cancellation_token) -> xtd::threading::tasks::task<result_t> {
return factory().start_new(
func, state, cancellation_token);}
200 template<
class result_t>
201 auto xtd::threading::tasks::basic_task<result_t>::yield() ->
task<result_t> {
202 co_await yield_awaiter {};
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:29
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
static auto capture() -> exception_dispatch_info
Creates an xtd::runtime::exception_services::exception_dispatch_info object that represents the speci...
Definition exception_dispatch_info.hpp:72
Propagates notification that operations should be canceled.
Definition cancellation_token.hpp:39
Provides support for creating and scheduling Task objects.
Definition task_factory.hpp:19
auto start_new(const xtd::func< result_t, const xtd::any_object & > &action, const xtd::any_object &state, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< result_t >
Creates and starts a task.
Definition task_factory.hpp:67
auto start_new(const xtd::func< result_t > &action, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< result_t >
Creates and starts a task.
Definition task_factory.hpp:47
auto start_new(const xtd::func< result_t, const xtd::any_object & > &action, const xtd::any_object &state) const -> xtd::threading::tasks::task< result_t >
Creates and starts a task.
Definition task_factory.hpp:57
auto start_new(const xtd::func< result_t > &action) const -> xtd::threading::tasks::task< result_t >
Creates and starts a task.
Definition task_factory.hpp:37
Represents an asynchronous operation.
Definition task_result.hpp:20
xtd::delegate< result_t(arguments_t... arguments)> func
Represents a delegate that has variables parameters and returns a value of the type specified by the ...
Definition func.hpp:27
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
@ ran_to_completion
The task completed execution successfully.
Definition task_status.hpp:35
@ faulted
The task completed due to an unhandled exception.
Definition task_status.hpp:39
@ canceled
The task acknowledged cancellation by throwing an OperationCanceledException with its own Cancellatio...
Definition task_status.hpp:37
xtd::intptr handle() noexcept
Gets the thread handle of the current thread.
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
auto as< xtd::int32 >(xtd::any value) -> xtd::int32
Casts a type into another type.
Definition __as_int32.hpp:36
delegate< void(arguments_t...)> action
Represents a xtd::delegate that has variable parameters and does not return a value.
Definition action.hpp:20
@ 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 <> class.