HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
hikogui
task.hpp
1
// Copyright Take Vos 2022.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5
#pragma once
6
7
#include "utility/module.hpp"
8
#include <coroutine>
9
#include <type_traits>
10
11
namespace
hi::inline
v1
{
12
13
template
<
typename
T>
14
class
task;
15
16
template
<
typename
T>
17
struct
task_promise_base
{
18
T _value;
19
20
void
return_void()
noexcept
21
{
22
hi_no_default
();
23
}
24
25
void
return_value(std::convertible_to<T>
auto
&&value)
noexcept
26
{
27
_value =
hi_forward
(value);
28
}
29
};
30
31
template
<>
32
struct
task_promise_base
<void> {
33
void
return_void()
noexcept
{}
34
};
35
36
template
<
typename
T>
37
struct
task_promise
:
task_promise_base
<T> {
38
using
value_type = T;
39
using
handle_type = std::coroutine_handle<task_promise<value_type>>;
40
using
task_type
=
task<value_type>
;
41
42
static
void
unhandled_exception()
43
{
44
throw
;
45
}
46
47
task<value_type>
get_return_object()
48
{
49
return
task_type
{handle_type::from_promise(*
this
)};
50
}
51
52
static
std::suspend_never initial_suspend()
noexcept
53
{
54
return
{};
55
}
56
57
static
std::suspend_never final_suspend()
noexcept
58
{
59
return
{};
60
}
61
};
62
67
template
<
typename
T =
void
>
68
class
task
{
69
public
:
70
using
value_type = T;
71
using
promise_type
=
task_promise<value_type>
;
72
using
handle_type = std::coroutine_handle<promise_type>;
73
74
explicit
task
(handle_type coroutine) : _coroutine(coroutine) {}
75
76
task
() =
default
;
77
~task
()
78
{
79
}
80
81
task
(
task
const
&) =
delete
;
82
task
(
task
&&) =
delete
;
83
task
&operator=(
task
const
&) =
delete
;
84
task
&operator=(
task
&&) =
delete
;
85
86
private
:
87
handle_type _coroutine;
88
};
89
90
}
// namespace hi::inline v1
hi_no_default
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition
assert.hpp:279
hi_forward
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition
utility.hpp:29
v1
DOXYGEN BUG.
Definition
algorithm.hpp:13
v1::task
Co-routine task.
Definition
task.hpp:68
v1::task_promise_base
Definition
task.hpp:17
v1::task_promise
Definition
task.hpp:37
Generated on Mon Apr 22 2024 12:52:30 for HikoGUI by
1.10.0