xtd
1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
xtd.core
include
xtd
threading
tasks
wtask.hpp
Go to the documentation of this file.
1
4
#pragma once
5
#include "
task_result.hpp
"
6
#include "
../../func.hpp
"
7
9
namespace
xtd
{
11
namespace
threading
{
13
namespace
tasks
{
14
template
<
typename
result_t =
void
>
15
class
wtask :
public
xtd::threading::tasks::task
<result_t> {
16
public
:
17
struct
promise_type
{
18
xtd::exception_services::exception_dispatch_info
exception;
19
xtd::ptr<xtd::threading::tasks::wtask<result_t>
> task;
20
std::coroutine_handle<promise_type> self;
21
22
auto
final_suspend()
noexcept
{
23
struct
final_awaiter {
24
promise_type
& promise;
25
26
bool
await_ready()
noexcept
{
return
false
;}
27
void
await_resume()
noexcept
{}
28
void
await_suspend(std::coroutine_handle<promise_type> handle)
noexcept
{
29
promise.task->start();
30
promise.self.destroy();
31
}
32
};
33
return
final_awaiter {*
this
};
34
}
35
xtd::threading::tasks::wtask<result_t>
get_return_object() {
36
task =
xtd::new_ptr<xtd::threading::tasks::wtask<result_t>
>();
37
self = std::coroutine_handle<promise_type>::from_promise(*
this
);
38
return
*task;
39
}
40
std::suspend_never initial_suspend() {
return
{};}
41
void
return_void() {}
42
void
unhandled_exception() {
/*exception = task->basic_task<result_t>::data_->exception;*/
}
43
};
44
45
struct
awaiter
{
46
xtd::threading::tasks::wtask<result_t>
& task;
47
48
bool
await_ready()
const
noexcept
{
return
task.is_completed();}
49
void
await_suspend(std::coroutine_handle<> handle) {task.continue_with([handle] {handle.resume();});}
50
void
await_resume() {
if
(task.is_faulted()) task.rethrow_exception();}
51
};
52
54
wtask() =
default
;
55
wtask(wtask&&) =
default
;
56
wtask(
const
wtask&) =
default
;
57
auto
operator=(wtask&&) -> wtask& =
default
;
58
auto
operator=(
const
wtask&) -> wtask& =
default
;
60
62
64
wtask(
const
xtd::func<result_t>
&
func
) : task<result_t>(
func
) {}
65
wtask
(
const
xtd::func<result_t>
&
func
,
const
xtd::threading::cancellation_token
&
cancellation_token
) :
task
<result_t>(
func
,
cancellation_token
) {}
66
wtask(
const
xtd::func<result_t, const xtd::any_object&>
&
func
,
const
xtd::any_object
& state) : task<result_t>(
func
, state) {}
68
69
~wtask() {
task<result_t>::wait
();}
71
73
75
auto
operator
co_await
()
noexcept
{
return
awaiter {*
this
};}
77
};
78
}
79
}
80
}
xtd::any_object
Represent a polymorphic wrapper capable of holding any type.
Definition
any_object.hpp:29
xtd::exception_services::exception_dispatch_info
Represents an exception whose state is captured at a certain point in code.
Definition
exception_dispatch_info.hpp:30
xtd::threading::cancellation_token
Propagates notification that operations should be canceled.
Definition
cancellation_token.hpp:39
xtd::threading::tasks::itask::wait
virtual auto wait() -> void=0
Waits for the task to complete execution.
xtd::threading::tasks::task
Represents an asynchronous operation.
Definition
task_result.hpp:20
xtd::threading::tasks::wtask
Definition
wtask.hpp:15
func.hpp
Contains xtd::func delegate.
xtd::func
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
xtd::ptr
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition
ptr.hpp:27
xtd::new_ptr
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
xtd::threading::tasks
The xtd::threading::tasks namespace provides types that simplify the work of writing concurrent and a...
Definition
basic_task.hpp:32
xtd::threading
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition
abandoned_mutex_exception.hpp:10
xtd
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition
abstract_object.hpp:8
xtd::threading::tasks::wtask::awaiter
Definition
wtask.hpp:45
xtd::threading::tasks::wtask::promise_type
Definition
wtask.hpp:17
task_result.hpp
Contains xtd::threading::tasks::task <result_t> class.
Generated on
for xtd by
Gammasoft
. All rights reserved.