xtd
1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
xtd.core
include
xtd
threading
tasks
task_completion_source.hpp
Go to the documentation of this file.
1
4
#pragma once
5
#include "
task_result.hpp
"
6
#include "
../cancellation_token_source.hpp
"
7
#include "
../../new_ptr.hpp
"
8
#include "
../../ptr.hpp
"
9
11
namespace
xtd
{
13
namespace
threading
{
15
namespace
tasks
{
16
template
<
typename
result_t>
17
class
task_completion_source :
public
xtd::object
{
18
public
:
20
22
task_completion_source() : data_ {
xtd::new_ptr<data>
([
this
] {
23
//if (data_->task.token().is_cancellation_requested()) throw task_canceled_exception {};
24
if
(data_->exception !=
null
)
throw
*data_->exception;
25
return
data_->result;
26
})} {}
28
30
32
auto
task()
const
noexcept
->
const
xtd::threading::tasks::task<result_t>
& {
return
data_->task;}
34
36
38
auto
set_canceled() ->
void
{
39
data_->cancellation.cancel();
40
data_->task.start();
41
}
42
43
template
<
typename
exception_t>
44
auto
set_exception(
const
exception_t&
exception
) ->
void
{
45
data_->exception =
xtd::ptr<xtd::exception>
{
exception
.template
memberwise_clone<exception_t>
().release()};
46
*data_->exception =
exception
;
47
data_->task.start();
48
}
49
50
auto
set_result(result_t&& result) ->
void
{
51
data_->result = std::forward<result_t>(result);
52
data_->task.start();
53
}
55
56
private
:
57
struct
data {
58
template
<
typename
func_t>
59
data(func_t
func
) {task = {
func
, cancellation.token()};}
60
xtd::threading::cancellation_token_source
cancellation;
61
result_t result;
62
xtd::ptr<xtd::exception>
exception
;
63
xtd::threading::tasks::task<result_t>
task;
64
};
65
xtd::ptr<data>
data_;
66
};
67
}
68
}
69
}
cancellation_token_source.hpp
Contains xtd::threading::cancellation_token_source class.
xtd::exception
Defines the base class for predefined exceptions in the xtd namespace.
Definition
exception.hpp:34
xtd::object
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition
object.hpp:40
xtd::object::memberwise_clone
auto memberwise_clone() const -> xtd::unique_ptr_object< object_t >
Creates a shallow copy of the current object.
xtd::threading::cancellation_token_source
Signals to a xtd::threading::cancellation_token that it should be canceled.
Definition
cancellation_token_source.hpp:38
xtd::threading::tasks::task
Represents an asynchronous operation.
Definition
task_result.hpp:20
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::null
null_ptr null
Represents a null pointer value.
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
itask.hpp:14
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
new_ptr.hpp
Contains xtd::new_ptr method.
ptr.hpp
Contains xtd::ptr type.
task_result.hpp
Contains xtd::threading::tasks::task <result_t> class.
Generated on
for xtd by
Gammasoft
. All rights reserved.