mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Finish the partial callback application feature
This commit is contained in:
parent
3b4fd82039
commit
28b1d57abb
@ -253,7 +253,7 @@ Continuables returning more then one value will evaluate to a future providing a
|
|||||||
|
|
||||||
Although the library has progressed very far there are still some candies missing:
|
Although the library has progressed very far there are still some candies missing:
|
||||||
|
|
||||||
- [ ] **Partial application**:
|
- [x] **Partial application**:
|
||||||
|
|
||||||
We could allow callbacks to be invoked with fewer arguments than expected:
|
We could allow callbacks to be invoked with fewer arguments than expected:
|
||||||
|
|
||||||
|
|||||||
@ -865,17 +865,24 @@ auto chain_continuation(Continuation&& continuation, Callback&& callback,
|
|||||||
static_assert(is_continuation<std::decay_t<Continuation>>{},
|
static_assert(is_continuation<std::decay_t<Continuation>>{},
|
||||||
"Expected a continuation!");
|
"Expected a continuation!");
|
||||||
|
|
||||||
|
// Wrap the callback into a partial callable callback
|
||||||
|
auto partial_callable = [callback = std::forward<Callback>(callback)](
|
||||||
|
auto&&... args) mutable {
|
||||||
|
return util::partial_invoke(std::move(callback),
|
||||||
|
std::forward<decltype(args)>(args)...);
|
||||||
|
};
|
||||||
|
|
||||||
auto hint = hint_of(util::identity_of(continuation));
|
auto hint = hint_of(util::identity_of(continuation));
|
||||||
auto next_hint = next_hint_of(util::identity_of(callback), hint);
|
auto next_hint = next_hint_of(util::identity_of(partial_callable), hint);
|
||||||
|
|
||||||
return make_continuable_base(
|
return make_continuable_base(
|
||||||
[
|
[
|
||||||
continuation = std::forward<Continuation>(continuation),
|
continuation = std::forward<Continuation>(continuation),
|
||||||
callback = std::forward<Callback>(callback),
|
partial_callable = std::move(partial_callable),
|
||||||
executor = std::forward<Executor>(executor)
|
executor = std::forward<Executor>(executor)
|
||||||
](auto&& nextCallback) mutable {
|
](auto&& nextCallback) mutable {
|
||||||
invoke_proxy(hint_of(util::identity_of(continuation)),
|
invoke_proxy(hint_of(util::identity_of(continuation)),
|
||||||
std::move(continuation), std::move(callback),
|
std::move(continuation), std::move(partial_callable),
|
||||||
std::move(executor),
|
std::move(executor),
|
||||||
std::forward<decltype(nextCallback)>(nextCallback));
|
std::forward<decltype(nextCallback)>(nextCallback));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -127,3 +127,14 @@ TYPED_TEST(single_dimension_tests, are_executable_through_dispatchers) {
|
|||||||
EXPECT_EQ(future.get(), canary);
|
EXPECT_EQ(future.get(), canary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(single_dimension_tests, are_partial_callable) {
|
||||||
|
EXPECT_ASYNC_RESULT(this->supply(1, 2).then([] {
|
||||||
|
// ...
|
||||||
|
}));
|
||||||
|
|
||||||
|
EXPECT_ASYNC_RESULT(this->supply(0xDF, 0xDD, 3, 4).then([](int a, int b) {
|
||||||
|
EXPECT_EQ(a, 0xDF);
|
||||||
|
EXPECT_EQ(b, 0xDD);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user