53 template<
typename result_t>
79 template<
typename result_t>
118 template<
typename result_t>
129 template<
typename result_t>
130 struct xtd::threading::tasks::basic_task<result_t>::yield_awaiter {
133 yield_awaiter() {task_.start();};
134 bool await_ready() const noexcept {
return task_.is_completed();}
135 void await_resume() {
if (task_.is_faulted()) task_.rethrow_exception();}
136 void await_suspend(std::coroutine_handle<> handle) {task_.continue_with_([handle] {
handle.resume();});}
139 template<
typename result_t>
140 auto basic_task<result_t>::completed_task() -> xtd::threading::tasks::task<result_t> {
141 auto task = xtd::threading::tasks::task<result_t> {};
143 task.basic_task<result_t>::data_->end_event.set();
147 template<
typename result_t>
148 auto basic_task<result_t>::continue_with(xtd::action<>&& continuation) -> xtd::threading::tasks::task<> {
149 auto call_now =
false;
151 lock_(data_->sync_root) {
153 if (is_completed()) call_now =
true;
156 if (call_now) run_continuation(data_->continuation_async);
157 return *data_->continuation;
160 template<
typename result_t>
161 auto basic_task<result_t>::continue_with(
xtd::func<xtd::threading::tasks::task<>>&& continuation_async) -> xtd::threading::tasks::task<xtd::threading::tasks::task<>> {
162 auto call_now =
false;
164 lock_(data_->sync_root) {
166 if (is_completed()) call_now =
true;
169 if (call_now) run_continuation(data_->continuation_async);
170 return *data_->continuation_async;
173 template<
typename result_t>
174 auto basic_task<result_t>::factory() noexcept -> const xtd::threading::tasks::
task_factory& {
175 static auto factory = xtd::threading::tasks::task_factory {};
179 template<
typename result_t>
180 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()));}
182 template<
typename result_t>
183 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);}
185 template<
typename result_t>
186 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);});}
188 template<
typename result_t>
189 auto basic_task<result_t>::delay(
xtd::int32 milliseconds_delay,
const xtd::threading::cancellation_token& cancellation_token) ->
task<> {
190 return xtd::threading::tasks::task<>::run([cancellation_token, milliseconds_delay]{xtd::threading::cancellation_token {cancellation_token}.wait_handle().wait_one(milliseconds_delay);}, cancellation_token);
193 template<
typename result_t>
194 auto basic_task<result_t>::from_cancelation(
const xtd::threading::cancellation_token& cancellation_token) ->
task<result_t> {
196 auto task = xtd::threading::tasks::task<result_t> {};
197 task.basic_task<>::data_->cancellation_token = cancellation_token;
199 task.basic_task<>::data_->end_event.set();
203 template<
typename result_t>
204 template<
typename from_exception_t>
205 auto basic_task<result_t>::from_exception(from_exception_t exception) -> xtd::threading::tasks::task<result_t> {
206 auto task = xtd::threading::tasks::task<result_t> {};
209 task.basic_task<>::data_->end_event.set();
213 template<
typename result_t>
214 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);}
215 template<
typename result_t>
216 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);}
217 template<
typename result_t>
219 template<
typename result_t>
220 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);}
222 template<
typename result_t>
223 template<
typename ...items_t>
224 auto xtd::threading::tasks::basic_task<result_t>::when_all(items_t&&... items) ->
task<> {
226 task<>::wait_all(std::forward<items_t>(items)...);
230 template<
typename result_t>
231 template<
typename ...items_t>
232 auto xtd::threading::tasks::basic_task<result_t>::when_any(items_t&&... items) ->
task<xtd::usize> {
234 return task<>::wait_any(std::forward<items_t>(items)...);
238 template<
typename result_t>
239 auto xtd::threading::tasks::basic_task<result_t>::yield() ->
task<result_t> {
240 co_await yield_awaiter {};
243 template<
typename result_t>
244 auto xtd::threading::tasks::basic_task<result_t>::run_continuation(
auto continuation) ->
void {
245 continuation->start();
246 continuation->wait();
249 template<
typename result1_t,
typename result2_t>
254 template<
typename result1_t,
typename result2_t>
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:30
static auto capture() -> exception_dispatch_info
Creates an xtd::exception_services::exception_dispatch_info object that represents the specified exce...
Definition exception_dispatch_info.hpp:65
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:40
Propagates notification that operations should be canceled.
Definition cancellation_token.hpp:39
Provides support for creating and scheduling Task objects.
Definition task_factory.hpp:22
auto start_new(auto &&action, const xtd::any_object &state, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(action(std::declval< const xtd::any_object & >()))> >
Creates and starts a task.
Definition task_factory.hpp:119
auto start_new(auto &&action) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
Creates and starts a task.
Definition task_factory.hpp:91
auto start_new(auto &&action, const xtd::any_object &state) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()(std::declval< const xtd::any_object & >()))> >
Creates and starts a task.
Definition task_factory.hpp:109
auto start_new(auto &&action, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
Creates and starts a task.
Definition task_factory.hpp:100
Represents an asynchronous operation.
Definition task_result.hpp:20
Definition iterable.hpp:15
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
#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
@ 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
auto handle() noexcept -> xtd::intptr
Gets the thread handle of the current thread.
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
auto as< xtd::int32 >(xtd::any value) -> xtd::int32
Casts a type into another type.
Definition __as_int32.hpp:36
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 <> class.