mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Add an operator| (pipe) for future folding and channels
This commit is contained in:
parent
09bae47e09
commit
612aeef0c8
@ -323,6 +323,19 @@ public:
|
||||
return std::move(*this).fail([](auto&&) {});
|
||||
}*/
|
||||
|
||||
/// The pipe operator | is an alias for the continuable::then method.
|
||||
///
|
||||
/// \param right The argument on the right-hand side to connect.
|
||||
///
|
||||
/// \returns See the corresponding continuable::then method for the
|
||||
/// explanation of the return type.
|
||||
///
|
||||
/// \since version 2.0.0
|
||||
template <typename T>
|
||||
auto operator|(T&& right) && {
|
||||
return std::move(*this).then(std::forward<T>(right));
|
||||
}
|
||||
|
||||
/// Invokes both continuable_base objects parallel and calls the
|
||||
/// callback with the result of both continuable_base objects.
|
||||
///
|
||||
|
||||
@ -69,17 +69,12 @@ struct my_callable {
|
||||
int main(int, char**) {
|
||||
http_request("github.com").flow(my_callable{});
|
||||
|
||||
http_request("github.com")
|
||||
.then([](std::string) {
|
||||
http_request("github.com") | [](std::string) {
|
||||
// ...
|
||||
return 0;
|
||||
})
|
||||
.fail([](std::error_condition) {
|
||||
} | [] {
|
||||
// ...
|
||||
})
|
||||
.then([] {
|
||||
// ...
|
||||
});
|
||||
};
|
||||
|
||||
http_request2("github.com")
|
||||
.then([](std::string) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user