Skip to content

Commit

Permalink
Working code with on, then, start and sync_wait algorithms.
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-parent committed Feb 27, 2024
1 parent 0a3759c commit cd2504d
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 73 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_test(NAME cli.version_matches COMMAND intro --version)
set_tests_properties(cli.version_matches PROPERTIES PASS_REGULAR_EXPRESSION "${PROJECT_VERSION}")

add_executable(tests tuple_tests.cpp initial_draft.cpp)
target_compile_options(tests PRIVATE -ftemplate-backtrace-limit=0)
target_link_libraries(
tests
PRIVATE chains::chains_warnings
Expand Down
172 changes: 99 additions & 73 deletions test/initial_draft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,28 @@ set on the receiver.

namespace chains::inline v1 {

/*
An scheduler is a function that takes a function and a set of arguments and applies the
arguments to the function. The application may be scheduled in another context and the scheduler
may inject additional arguments into the function.
*/

template <class F>
struct scheduler {
template <class... Args>
using result_type = std::invoke_result_t<F>;
F _f;
template <class... Args>
auto operator()(Args&&... args) const {
return std::invoke(_f, std::forward<Args>(args)...);
}
};

/*
segment is invoked with a receiver -
*/

template <class Injects = std::tuple<>, class Applicator, class... Fs>
template <class T>
struct type {};

template <class Injects, class Applicator, class... Fs>
class segment;

#if 0
template <class Injects, class Applicator, class... Fs>
inline auto make_segment(Applicator&& apply, Fs&&... fs) {
return segment<Injects, std::decay_t<Applicator>, std::decay_t<Fs>...>{
std::forward<Applicator>(apply), std::forward<Fs>(fs)...};
}
#endif

template <class Injects, class Applicator, class... Fs>
class segment {

Check failure on line 49 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, gcc-11, Ninja Multi-Config, Debug, OFF, OFF)

class 'segment' defines a copy constructor, a copy assignment operator, a move constructor and a move assignment operator but does not define a destructor [cppcoreguidelines-special-member-functions,hicpp-special-member-functions,-warnings-as-errors]

Check failure on line 49 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, gcc-11, Ninja Multi-Config, Release, OFF, OFF)

class 'segment' defines a copy constructor, a copy assignment operator, a move constructor and a move assignment operator but does not define a destructor [cppcoreguidelines-special-member-functions,hicpp-special-member-functions,-warnings-as-errors]

Check failure on line 49 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, OFF, OFF)

class 'segment' defines a copy constructor, a copy assignment operator, a move constructor and a move assignment operator but does not define a destructor [cppcoreguidelines-special-member-functions,hicpp-special-member-functions,-warnings-as-errors]

Check failure on line 49 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, OFF, OFF)

class 'segment' defines a copy constructor, a copy assignment operator, a move constructor and a move assignment operator but does not define a destructor [cppcoreguidelines-special-member-functions,hicpp-special-member-functions,-warnings-as-errors]
std::tuple<Fs...> _functions;
Applicator _apply;
Expand All @@ -67,9 +64,9 @@ class segment {
return tuple_compose(std::move(_functions))(std::forward<Args>(args)...);
}

explicit segment(Applicator&& apply, std::tuple<Fs...>&& functions)
explicit segment(type<Injects>, Applicator&& apply, std::tuple<Fs...>&& functions)

Check warning on line 67 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L67

Added line #L67 was not covered by tests

Check failure on line 67 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, gcc-11, Ninja Multi-Config, Debug, OFF, OFF)

all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter,-warnings-as-errors]

Check failure on line 67 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, gcc-11, Ninja Multi-Config, Release, OFF, OFF)

all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter,-warnings-as-errors]

Check failure on line 67 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, OFF, OFF)

all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter,-warnings-as-errors]

Check failure on line 67 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, OFF, OFF)

all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter,-warnings-as-errors]
: _functions{std::move(functions)}, _apply{std::move(apply)} {}
explicit segment(Applicator&& apply, Fs&&... functions)
explicit segment(type<Injects>, Applicator&& apply, Fs&&... functions)

Check warning on line 69 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L69

Added line #L69 was not covered by tests

Check failure on line 69 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, gcc-11, Ninja Multi-Config, Debug, OFF, OFF)

all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter,-warnings-as-errors]

Check failure on line 69 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, gcc-11, Ninja Multi-Config, Release, OFF, OFF)

all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter,-warnings-as-errors]

Check failure on line 69 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, OFF, OFF)

all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter,-warnings-as-errors]

Check failure on line 69 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, OFF, OFF)

all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter,-warnings-as-errors]
: _functions{std::move(functions)...}, _apply{std::move(apply)} {}

/*
Expand All @@ -83,8 +80,9 @@ class segment {

template <class F>
auto append(F&& f) && {
return chains::segment{std::move(_apply), std::tuple_cat(std::move(_functions),
std::tuple{std::forward<F>(f)})};
return chains::segment{
type<Injects>{}, std::move(_apply),

Check warning on line 84 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L84

Added line #L84 was not covered by tests
std::tuple_cat(std::move(_functions), std::tuple{std::forward<F>(f)})};
}

#if 0
Expand Down Expand Up @@ -131,25 +129,20 @@ constexpr auto fold_over(Fold fold, Segments&& segments) {

} // namespace detail

#error "We need to account for the segment providing the argument to the tuple in the compose."

template <class Segment, class... Args>
using segment_result_type =
decltype(std::declval<Segment>().result_type_helper(std::declval<Args>()...));

/*
simplify this code by handing the multi-argument case earlier (somehow).
*/

template <class Tail, class Applicator, class... Fs>
template <class Tail, class Injects, class Applicator, class... Fs>
class chain {
Tail _tail;
segment<Applicator, Fs...> _head;
segment<Injects, Applicator, Fs...> _head;

/// Return a lambda with the signature of
/// head( tail<n>( tail<1>( tail<0>( auto&& args... ) ) ) )
/// for computing the result type of this chain.
static consteval auto result_type_helper(Tail&& tail, segment<Applicator, Fs...>&& head) {
static consteval auto result_type_helper(Tail&& tail,
segment<Injects, Applicator, Fs...>&& head) {
return detail::fold_over(
[](auto fold, auto&& first, auto&&... rest) {
if constexpr (sizeof...(rest) == 0) {
Expand All @@ -163,7 +156,7 @@ class chain {
};
}
},
std::tuple_cat(std::move(tail), std::tuple{std::move(head)}));
std::tuple_cat(STLAB_FWD(tail), std::tuple{STLAB_FWD(head)}));
}

template <class R>
Expand All @@ -185,12 +178,27 @@ class chain {
std::tuple_cat(std::move(_tail), std::tuple{std::move(_head)}));
}

template <class... Args>
struct result_type_void_injects {
using type = decltype(result_type_helper(
std::declval<Tail>(),
std::declval<segment<Injects, Applicator, Fs...>>())(std::declval<Args>()...));
};

template <class... Args>
struct result_type_injects {
using type = decltype(result_type_helper(
std::declval<Tail>(), std::declval<segment<Injects, Applicator, Fs...>>())(
std::declval<Injects>(), std::declval<Args>()...));
};

public:
template <class... Args>
using result_type = decltype(result_type_helper(
std::declval<Tail>(), std::declval<segment<Applicator, Fs...>>())(std::declval<Args>()...));
using result_type = std::conditional_t<std::is_same_v<Injects, void>,

Check failure on line 197 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

missing 'typename' prior to dependent type name 'std::conditional_t<std::is_same_v<Injects, void>, result_type_void_injects<Args...>, result_type_injects<Args...>>::type'

Check failure on line 197 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

missing 'typename' prior to dependent type name 'std::conditional_t<std::is_same_v<Injects, void>, result_type_void_injects<Args...>, result_type_injects<Args...>>::type'

Check failure on line 197 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (windows-2019, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

missing 'typename' prior to dependent type name 'std::conditional_t<std::is_same_v<Injects, void>, result_type_void_injects<Args...>, result_type_injects<Args...>>::type'

Check failure on line 197 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (windows-2019, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

missing 'typename' prior to dependent type name 'std::conditional_t<std::is_same_v<Injects, void>, result_type_void_injects<Args...>, result_type_injects<Args...>>::type'
result_type_void_injects<Args...>,
result_type_injects<Args...>>::type;

explicit chain(Tail&& tail, segment<Applicator, Fs...>&& head)
explicit chain(Tail&& tail, segment<Injects, Applicator, Fs...>&& head)

Check warning on line 201 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L201

Added line #L201 was not covered by tests
: _tail{std::move(tail)}, _head{std::move(head)} {}

/*
Expand All @@ -209,8 +217,8 @@ class chain {
return chains::chain{std::move(_tail), std::move(_head).append(std::forward<F>(f))};
}

template <class I, class... Gs>
auto append(segment<I, Gs...>&& head) && {
template <class Jnjects, class I, class... Gs>
auto append(segment<Jnjects, I, Gs...>&& head) && {

Check warning on line 221 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L221

Added line #L221 was not covered by tests
return chains::chain{std::tuple_cat(std::move(_tail), std::make_tuple(std::move(_head))),
std::move(head)};
}
Expand All @@ -221,6 +229,7 @@ class chain {
std::forward<Args>(args)...);
}

#if 0
template <class... Args>
[[deprecated]] auto operator()(Args&&... args) && {
using result_t = result_type<Args...>;
Expand All @@ -229,23 +238,25 @@ class chain {
invoke(std::move(receiver), std::forward<Args>(args)...);
return std::move(future);
}
#endif

template <class F>
friend auto operator|(chain&& c, F&& f) {
return std::move(c).append(std::forward<F>(f));
}

template <class I, class... Gs>
friend auto operator|(chain&& c, segment<I, Gs...>&& head) {
template <class Jnjects, class I, class... Gs>
friend auto operator|(chain&& c, segment<Jnjects, I, Gs...>&& head) {

Check warning on line 249 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L249

Added line #L249 was not covered by tests
return std::move(c).append(std::move(head));
}
};

template <class Tail, class Applicator, class... Fs>
chain(Tail&& tail, segment<Applicator, Fs...>&& head) -> chain<Tail, Applicator, Fs...>;
template <class Tail, class Injects, class Applicator, class... Fs>
chain(Tail&& tail, segment<Injects, Applicator, Fs...>&& head)
-> chain<Tail, Injects, Applicator, Fs...>;

template <class F, class Applicator, class... Fs>
inline auto operator|(segment<Applicator, Fs...>&& head, F&& f) {
template <class F, class Injects, class Applicator, class... Fs>
inline auto operator|(segment<Injects, Applicator, Fs...>&& head, F&& f) {

Check warning on line 259 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L259

Added line #L259 was not covered by tests
return chain{std::tuple<>{}, std::move(head).append(std::forward<F>(f))};
}

Expand All @@ -266,22 +277,23 @@ last item in the chain as a segment.
*/
template <class E>
inline auto on(E&& executor) {
return segment{[_executor = std::forward<E>(executor)](auto&& f, auto&&... args) mutable {
std::move(_executor)(
[_f = std::forward<decltype(f)>(f),
_args = std::tuple{std::forward<decltype(args)>(args)...}]() mutable noexcept {
std::apply(std::move(_f), std::move(_args));
});
return std::monostate{};
}};
return segment{
type<void>{}, [_executor = std::forward<E>(executor)](auto&& f, auto&&... args) mutable {

Check warning on line 281 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L281

Added line #L281 was not covered by tests
std::move(_executor)(
[_f = std::forward<decltype(f)>(f),

Check warning on line 283 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L283

Added line #L283 was not covered by tests
_args = std::tuple{std::forward<decltype(args)>(args)...}]() mutable noexcept {
std::apply(std::move(_f), std::move(_args));

Check warning on line 285 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L285

Added line #L285 was not covered by tests
});
// return std::monostate{};
}};

Check warning on line 288 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L288

Added line #L288 was not covered by tests
}

/*
The `then` algorithm takes a future and returns a segment (chain) that will schedule the
segment as a continuation of the future.
The segment returns void so the future is (kind of) detached - but this should be done without
the overhead of a future::detach.
The segment returns void so the future is (kind of) detached - but this should be done
without the overhead of a future::detach.
How is cancellation handled here? Let's say we have this:
Expand All @@ -293,9 +305,11 @@ inline auto on(E&& executor) {

template <class F>
inline auto then(F&& future) {
return chain{std::tuple<>{}, segment{[_future = std::forward<F>(future)](auto&& f) mutable {
return std::move(_future).then(std::forward<decltype(f)>(f));
}}};
return chain{std::tuple<>{},

Check warning on line 308 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L307-L308

Added lines #L307 - L308 were not covered by tests
segment{type<typename std::decay_t<F>::result_type>{},
[_future = std::forward<F>(future)](auto&& f) mutable {
return std::move(_future).then(std::forward<decltype(f)>(f));
}}};

Check warning on line 312 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L310-L312

Added lines #L310 - L312 were not covered by tests
}

// TODO: (sean-parent) - should we make this pipeable?
Expand All @@ -305,14 +319,23 @@ template <class Chain, class... Args>
inline auto start(Chain&& chain, Args&&... args) {

Check warning on line 319 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L319

Added line #L319 was not covered by tests
using result_t = Chain::template result_type<Args...>;

Check failure on line 320 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

expected a type

Check failure on line 320 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

expected ';' after alias declaration

Check failure on line 320 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

expected a type

Check failure on line 320 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

expected ';' after alias declaration
using invoke_t = decltype(std::forward<Chain>(chain).invoke(
std::move(std::declval<stlab::packaged_task<result_t>>()), std::forward<Args>(args)...));
auto p = std::make_shared<std::optional<invoke_t>>();
auto [receiver, future] =
stlab::package<result_t(result_t)>(stlab::immediate_executor, [p](auto&& value) {
return std::forward<decltype(value)>(value);
});
*p = std::forward<Chain>(chain).invoke(std::move(receiver), std::forward<Args>(args)...);
return std::move(future);
std::declval<stlab::packaged_task<result_t>>(), std::forward<Args>(args)...));

Check failure on line 322 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

use of undeclared identifier 'result_t'; did you mean 'stlab::detail::result_t'?

Check failure on line 322 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

use of undeclared identifier 'result_t'

Check failure on line 322 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

use of undeclared identifier 'result_t'; did you mean 'stlab::detail::result_t'?

Check failure on line 322 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

use of undeclared identifier 'result_t'
if constexpr (std::is_same_v<invoke_t, void>) {

Check failure on line 323 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

use of undeclared identifier 'invoke_t'

Check failure on line 323 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

use of undeclared identifier 'invoke_t'
auto [receiver, future] =
stlab::package<result_t(result_t)>(stlab::immediate_executor, [](auto&& value) {

Check failure on line 325 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

use of undeclared identifier 'result_t'

Check failure on line 325 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

use of undeclared identifier 'result_t'
return std::forward<decltype(value)>(value);

Check warning on line 326 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L325-L326

Added lines #L325 - L326 were not covered by tests
});
std::forward<Chain>(chain).invoke(std::move(receiver), std::forward<Args>(args)...);
return std::move(future);
} else {

Check warning on line 330 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L329-L330

Added lines #L329 - L330 were not covered by tests
auto p = std::make_shared<std::optional<invoke_t>>();

Check failure on line 331 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

use of undeclared identifier 'invoke_t'

Check failure on line 331 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

use of undeclared identifier 'invoke_t'
auto [receiver, future] =
stlab::package<result_t(result_t)>(stlab::immediate_executor, [p](auto&& value) {

Check failure on line 333 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Release, ON, OFF)

use of undeclared identifier 'result_t'

Check failure on line 333 in test/initial_draft.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-20.04, llvm-15.0.2, Ninja Multi-Config, Debug, ON, OFF)

use of undeclared identifier 'result_t'
return std::forward<decltype(value)>(value);
});
*p = std::forward<Chain>(chain).invoke(std::move(receiver), std::forward<Args>(args)...);
return std::move(future);
}
}

template <class Receiver>
Expand Down Expand Up @@ -355,8 +378,8 @@ inline auto sync_wait(Chain&& chain, Args&&... args) {
} receiver;

Check warning on line 378 in test/initial_draft.cpp

View check run for this annotation

Codecov / codecov/patch

test/initial_draft.cpp#L377-L378

Added lines #L377 - L378 were not covered by tests

/*
REVISIT: (sean-parent) - chain invoke doesn't work with std::ref(receiver). We should fix
that but for now create a receiver-ref.
REVISIT: (sean-parent) - chain invoke doesn't work with std::ref(receiver). We should
fix that but for now create a receiver-ref.
*/

auto hold = std::forward<Chain>(chain).invoke(receiver_ref<receiver_t>{&receiver},
Expand All @@ -372,12 +395,13 @@ inline auto sync_wait(Chain&& chain, Args&&... args) {
}

/*
TODO: The ergonimics of chains are painful with three arguements. We could reduce to a single
argument or move to a concept? Here I really want the forward reference to be an rvalue ref.
TODO: The ergonimics of chains are painful with three arguements. We could reduce to a
single argument or move to a concept? Here I really want the forward reference to be an
rvalue ref.
The implementation of sync_wait is complicated by the fact that the promise is currently hard/
wired into the chain. sync_wait needs to be able to invoke the promise/receiver - _then_ flag
the condition that it is ready.
The implementation of sync_wait is complicated by the fact that the promise is currently
hard/ wired into the chain. sync_wait needs to be able to invoke the promise/receiver -
_then_ flag the condition that it is ready.
*/

} // namespace chains::inline v1
Expand All @@ -398,6 +422,8 @@ TEST_CASE("Initial draft", "[initial_draft]") {
cout << "Hello from thread: " << std::this_thread::get_id() << "\n";
return 42;
};
// std::cout << typeid(decltype(a0)::result_type<>).name() << "\n";
// auto future = start(std::move(a0));

auto a1 = std::move(a0) | on(default_executor) | [](int x) {
cout << "received: " << x << " on thread: " << std::this_thread::get_id() << "\n";
Expand All @@ -409,7 +435,7 @@ TEST_CASE("Initial draft", "[initial_draft]") {
cout << "Ready to go async!\n";

#if 0
auto a2 = then(std::move(a1)()) | [](std::string s){
auto a2 = then(std::move(a1)) | [](std::string s) {
cout << s << "<-- \n";
return 0;
};
Expand Down Expand Up @@ -437,7 +463,7 @@ TEST_CASE("Initial draft", "[initial_draft]") {
// std::cout << await(start(std::move(a1))) << "\n";

auto future = start(std::move(a1));
auto a2 = then(future) | [](std::string s) { std::cout << s << "<-- \n"; };
auto a2 = then(future) | [](std::string s) { return s + "<-- \n"; };

std::cout << sync_wait(std::move(a2)) << "\n";

Expand Down

0 comments on commit cd2504d

Please sign in to comment.