File tree Expand file tree Collapse file tree 6 files changed +62
-5
lines changed Expand file tree Collapse file tree 6 files changed +62
-5
lines changed Original file line number Diff line number Diff line change 1
1
cmake_minimum_required (VERSION 3.0.0 )
2
- project (conduit VERSION 0.1.2 LANGUAGES CXX )
2
+ project (conduit VERSION 0.2.0 LANGUAGES CXX )
3
3
4
4
option (CONDUIT_Install "Install CMake targets during install step." ON )
5
5
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ rm -rf conduit
74
74
75
75
On Ubuntu, installation would be as follows:
76
76
77
- 1 . Download [ conduit.deb] ( https://github.com/functionalperez/conduit/releases/download/v0.1.2 /conduit_0.1.2 -0_all.deb ) (This is a download link)
77
+ 1 . Download [ conduit.deb] ( https://github.com/functionalperez/conduit/releases/download/v0.2.0 /conduit_0.2.0 -0_all.deb ) (This is a download link)
78
78
2 . Go to your downloads folder (` cd ~/Downloads ` )
79
79
3 . Run ` sudo apt install ./conduit.deb ` (or just double-click the file to open it in the installer)
80
80
Original file line number Diff line number Diff line change 1
- 0.1.2
1
+ 0.2.0
Original file line number Diff line number Diff line change
1
+ #pragma once
2
+ #include < conduit/mixin/resumable.hpp>
3
+ #include < conduit/util/concepts.hpp>
4
+ #include < conduit/util/tag_types.hpp>
5
+
6
+ namespace conduit {
7
+ // clang-format off
8
+ template <class Func >
9
+ concept on_suspend_callback = requires (Func func, std::coroutine_handle<> h) {
10
+ { func (h) } -> same_as<void >;
11
+ };
12
+
13
+ template <class Func >
14
+ concept on_resume_callback = requires (Func func) {
15
+ { func (tags::on_resume) };
16
+ };
17
+ // clang-format on
18
+ } // namespace conduit
19
+
20
+ namespace conduit ::async {
21
+ template <class Func >
22
+ struct suspend_invoke_container {
23
+ [[no_unique_address]] Func on_suspend;
24
+ };
25
+
26
+ template <class Func >
27
+ struct suspend_invoke : suspend_invoke_container<Func>,
28
+ mixin::Resumable<suspend_invoke<Func>> {
29
+ using suspend_invoke_container<Func>::on_suspend;
30
+ using mixin::Resumable<suspend_invoke<Func>>::await_resume;
31
+ decltype (auto ) await_resume() {
32
+ if constexpr (conduit::on_resume_callback<decltype (on_suspend)>) {
33
+ return on_suspend (tags::on_resume);
34
+ } else {
35
+ return ;
36
+ }
37
+ }
38
+ };
39
+
40
+ template <on_suspend_callback Func>
41
+ suspend_invoke (Func) -> suspend_invoke<Func>;
42
+ } // namespace conduit::async
Original file line number Diff line number Diff line change 2
2
#include < conduit/util/concepts.hpp>
3
3
4
4
namespace conduit ::tags {
5
+ struct on_resume_t {
6
+ explicit on_resume_t () = default;
7
+ };
8
+ constexpr auto on_resume = on_resume_t ();
9
+
5
10
struct get_promise_t {
6
11
explicit get_promise_t () = default;
7
12
};
@@ -30,4 +35,4 @@ struct nothing_t {
30
35
};
31
36
constexpr auto nothing = nothing_t ();
32
37
33
- } // namespace conduit
38
+ } // namespace conduit::tags
Original file line number Diff line number Diff line change 6
6
#include < conduit/source.hpp>
7
7
#include < conduit/task.hpp>
8
8
#include < conduit/async/destroy.hpp>
9
+ #include < conduit/async/suspend_invoke.hpp>
9
10
#include < cstdio>
10
11
#include < cstdlib>
11
12
#include < iostream>
@@ -72,7 +73,6 @@ future<std::string> test_generator(std::string on_success) {
72
73
co_return std::string (begin (g), end (g));
73
74
}
74
75
75
-
76
76
future<std::string> test_on_suspend (std::string on_success) {
77
77
std::string result;
78
78
auto f = [](std::coroutine_handle<> h, std::string& result, std::string& on_success) {
@@ -112,6 +112,15 @@ future<std::string> test_source(std::string on_success) {
112
112
co_return result;
113
113
}
114
114
115
+ future<std::string> test_suspend_invoke (std::string on_success) {
116
+ std::string result;
117
+ co_await async::suspend_invoke{[&](std::coroutine_handle<> h) {
118
+ result = on_success;
119
+ h.resume ();
120
+ }};
121
+ co_return result;
122
+ }
123
+
115
124
future<std::string> test_task (std::string on_success) {
116
125
auto coro = [&](std::string& s) -> task {
117
126
s = on_success;
@@ -133,6 +142,7 @@ coroutine run_tests() {
133
142
RUN_TEST (test_on_suspend);
134
143
RUN_TEST (test_recursive_generator);
135
144
RUN_TEST (test_source);
145
+ RUN_TEST (test_suspend_invoke);
136
146
RUN_TEST (test_task);
137
147
}
138
148
You can’t perform that action at this time.
0 commit comments