Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tom Niget
typon
Commits
09e7f7a0
Commit
09e7f7a0
authored
Apr 08, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP Lazy coroutines
parent
7e33cffa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
27 deletions
+42
-27
rt/result.hpp
rt/result.hpp
+2
-6
rt/task.hpp
rt/task.hpp
+40
-21
No files found.
rt/result.hpp
View file @
09e7f7a0
...
@@ -13,7 +13,6 @@ namespace typon
...
@@ -13,7 +13,6 @@ namespace typon
template
<
typename
T
>
template
<
typename
T
>
struct
result
struct
result
{
{
std
::
exception_ptr
_exception
;
std
::
exception_ptr
_exception
;
union
union
{
{
...
@@ -56,14 +55,12 @@ namespace typon
...
@@ -56,14 +55,12 @@ namespace typon
}
}
return
std
::
move
(
_value
);
return
std
::
move
(
_value
);
}
}
};
};
template
<
typename
T
>
template
<
typename
T
>
struct
result
<
T
&>
struct
result
<
T
&>
{
{
T
*
_value
;
T
*
_value
;
std
::
exception_ptr
_exception
;
std
::
exception_ptr
_exception
;
...
@@ -85,16 +82,16 @@ namespace typon
...
@@ -85,16 +82,16 @@ namespace typon
}
}
return
*
_value
;
return
*
_value
;
}
}
};
};
template
<
>
template
<
>
struct
result
<
void
>
struct
result
<
void
>
{
{
std
::
exception_ptr
_exception
;
std
::
exception_ptr
_exception
;
void
return_void
()
noexcept
{}
void
unhandled_exception
()
noexcept
void
unhandled_exception
()
noexcept
{
{
_exception
=
std
::
current_exception
();
_exception
=
std
::
current_exception
();
...
@@ -107,7 +104,6 @@ namespace typon
...
@@ -107,7 +104,6 @@ namespace typon
std
::
rethrow_exception
(
_exception
);
std
::
rethrow_exception
(
_exception
);
}
}
}
}
};
};
}
}
...
...
rt/task.hpp
View file @
09e7f7a0
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#include <coroutine>
#include <coroutine>
#include <promise.hpp>
#include <result.hpp>
#include <result.hpp>
...
@@ -11,49 +10,69 @@ namespace typon
...
@@ -11,49 +10,69 @@ namespace typon
{
{
template
<
typename
T
=
void
>
template
<
typename
T
=
void
>
//struct [[nodiscard]] task
struct
[[
nodiscard
]]
task
struct
task
{
{
struct
promise_type
;
struct
promise_type
;
std
::
coroutine_handle
<
promise_type
>
_coroutine
;
std
::
coroutine_handle
<
promise_type
>
_coroutine
;
result
<
T
>
_result
;
struct
promise_type
:
promise
<
T
>
~
task
()
{
{
_coroutine
.
destroy
();
}
// std::coroutine_handle<> _continuation;
struct
promise_type
:
result
<
T
>
{
std
::
coroutine_handle
<>
_continuation
;
struct
final_awaitable
:
std
::
suspend_always
{
template
<
typename
Promise
>
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<
Promise
>
coroutine
)
noexcept
{
return
coroutine
.
promise
().
_continuation
;
}
};
task
get_return_object
()
noexcept
task
get_return_object
()
noexcept
{
{
task
_task
{
std
::
coroutine_handle
<
promise_type
>::
from_promise
(
*
this
),
result
<
T
>
{}
};
return
{
std
::
coroutine_handle
<
promise_type
>::
from_promise
(
*
this
)
};
this
->
_result
=
std
::
addressof
(
_task
.
_result
);
return
_task
;
}
}
std
::
suspend_
never
initial_suspend
()
noexcept
std
::
suspend_
always
initial_suspend
()
noexcept
{
{
return
{};
return
{};
}
}
std
::
suspend_never
final_suspend
()
noexcept
final_awaitable
final_suspend
()
noexcept
{
{
return
{};
return
{};
}
}
};
};
// auto operator co_await() const&& noexcept
auto
operator
co_await
()
const
&&
noexcept
// {
{
// struct awaitable
struct
awaitable
// {
{
// bool await_ready() noexcept
std
::
coroutine_handle
<
promise_type
>
_coroutine
;
// {
bool
await_ready
()
{
return
false
;
};
std
::
coroutine_handle
<>
await_suspend
(
std
::
coroutine_handle
<>
awaiting_coroutine
)
noexcept
{
_coroutine
.
promise
().
_continuation
=
awaiting_coroutine
;
return
_coroutine
;
}
// }
decltype
(
auto
)
await_resume
()
// };
{
// }
return
_coroutine
.
promise
().
get
();
}
};
return
awaitable
{
_coroutine
};
}
};
};
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment