2
0
mirror of https://github.com/boostorg/cobalt.git synced 2026-01-19 04:02:16 +00:00

removed leaf support.

Closes #213
This commit is contained in:
Klemens Morgenstern
2024-12-13 11:15:21 +08:00
parent 2a4975200b
commit cd2ea28a53
10 changed files with 1 additions and 317 deletions

View File

@@ -30,7 +30,6 @@ deps = [
'libs/intrusive',
'libs/io',
'libs/iterator',
'libs/leaf',
'libs/mpl',
'libs/move',
'libs/mp11',

View File

@@ -52,7 +52,6 @@ if (NOT BOOST_COBALT_IS_ROOT)
Boost::config
Boost::core
Boost::intrusive
Boost::leaf
Boost::mp11
Boost::preprocessor
Boost::smart_ptr

View File

@@ -17,7 +17,6 @@ constant boost_dependencies :
/boost/context//boost_context
/boost/core//boost_core
/boost/intrusive//boost_intrusive
/boost/leaf//boost_leaf
/boost/mp11//boost_mp11
/boost/preprocessor//boost_preprocessor
/boost/smart_ptr//boost_smart_ptr

View File

@@ -77,7 +77,6 @@ include::reference/result.adoc[]
include::reference/async_for.adoc[]
include::reference/error.adoc[]
include::reference/config.adoc[]
include::reference/leaf.adoc[]
include::reference/experimental/context.adoc[]

View File

@@ -1,26 +0,0 @@
[#leaf]
== cobalt/leaf.hpp
Async provides integration with boost.leaf.
It provides functions similar to leaf that take an <<awaitable, awaitables>>
instead of a function object and return an <<awaitable, awaitable>>.
[source,cpp]
----
template<awaitable TryAwaitable, typename ... H >
auto try_catch(TryAwaitable && try_coro, H && ... h );
template<awaitable TryAwaitable, typename ... H >
auto try_handle_all(TryAwaitable && try_coro, H && ... h );
template<awaitable TryAwaitable, typename ... H >
auto try_handle_some(TryAwaitable && try_coro, H && ... h );
----
See the leaf documentation for details.
- https://www.boost.org/doc/libs/master/libs/leaf/doc/html/index.html#try_catch[try_catch]
- https://www.boost.org/doc/libs/master/libs/leaf/doc/html/index.html#try_handle_all[try_handle_all]
- https://www.boost.org/doc/libs/master/libs/leaf/doc/html/index.html#try_handle_some[try_handle_some]

View File

@@ -17,7 +17,6 @@
#include <boost/cobalt/gather.hpp>
#include <boost/cobalt/generator.hpp>
#include <boost/cobalt/join.hpp>
#include <boost/cobalt/leaf.hpp>
#include <boost/cobalt/main.hpp>
#include <boost/cobalt/op.hpp>
#include <boost/cobalt/promise.hpp>

View File

@@ -1,85 +0,0 @@
// Copyright (c) 2023 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_COBALT_DETAIL_LEAF_HPP
#define BOOST_COBALT_DETAIL_LEAF_HPP
#include <boost/cobalt/detail/await_result_helper.hpp>
#include <boost/leaf/config.hpp>
#include <boost/leaf/handle_errors.hpp>
namespace boost::cobalt::detail
{
template<typename Awaitable, typename ... H>
struct [[nodiscard]] try_catch_awaitable
{
Awaitable aw;
std::tuple<H...> handler;
bool await_ready() {return aw.await_ready(); }
template<typename Promise>
auto await_suspend(std::coroutine_handle<Promise> h) {return aw.await_suspend(h);}
auto await_resume()
{
return std::apply(
[this](auto && ... h)
{
return leaf::try_catch(
[this]{return std::move(aw).await_resume();},
std::move(h)...);
}, std::move(handler));
}
};
template<typename Awaitable, typename ... H>
struct [[nodiscard]] try_handle_all_awaitable
{
Awaitable aw;
std::tuple<H...> handler;
bool await_ready() {return aw.await_ready(); }
template<typename Promise>
auto await_suspend(std::coroutine_handle<Promise> h) {return aw.await_suspend(h);}
auto await_resume()
{
return std::apply(
[this](auto && ... h)
{
return leaf::try_handle_all(
[this]{return std::move(aw).await_resume();},
std::move(h)...);
}, std::move(handler));
}
};
template<typename Awaitable, typename ... H>
struct [[nodiscard]] try_handle_some_awaitable
{
Awaitable aw;
std::tuple<H...> handler;
bool await_ready() {return aw.await_ready(); }
template<typename Promise>
auto await_suspend(std::coroutine_handle<Promise> h) {return aw.await_suspend(h);}
auto await_resume()
{
return std::apply(
[this](auto && ... h)
{
return leaf::try_handle_some(
[this]{return std::move(aw).await_resume();},
std::move(h)...);
}, std::move(handler));
}
};
}
#endif //BOOST_COBALT_DETAIL_LEAF_HPP

View File

@@ -1,51 +0,0 @@
// Copyright (c) 2023 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_COBALT_LEAF_HPP
#define BOOST_COBALT_LEAF_HPP
#include <boost/cobalt/detail/leaf.hpp>
#include <boost/leaf/config.hpp>
#include <boost/leaf/handle_errors.hpp>
namespace boost::cobalt
{
template<awaitable TryAwaitable, typename ... H >
auto try_catch(TryAwaitable && try_coro, H && ... h )
{
return detail::try_catch_awaitable<
std::decay_t<decltype(detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)))>, H...>
{
detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)),
{std::forward<H>(h)...}
};
}
template<awaitable TryAwaitable, typename ... H >
auto try_handle_all(TryAwaitable && try_coro, H && ... h )
{
return detail::try_handle_all_awaitable<
std::decay_t<decltype(detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)))>, H...>
{
detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)),
{std::forward<H>(h)...}
};
}
template<awaitable TryAwaitable, typename ... H >
auto try_handle_some(TryAwaitable && try_coro, H && ... h )
{
return detail::try_handle_some_awaitable<
std::decay_t<decltype(detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)))>, H...>
{
detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)),
{std::forward<H>(h)...}
};
}
}
#endif //BOOST_COBALT_LEAF_HPP

View File

@@ -9,7 +9,7 @@ target_link_libraries(boost_cobalt_static_tests Boost::cobalt)
add_executable(boost_cobalt_main EXCLUDE_FROM_ALL main.cpp)
add_executable(boost_cobalt_main_compile EXCLUDE_FROM_ALL main_compile.cpp)
add_executable(boost_cobalt_basic_tests EXCLUDE_FROM_ALL
async_for.cpp test_main.cpp promise.cpp with.cpp op.cpp handler.cpp join.cpp race.cpp this_coro.cpp leaf.cpp
async_for.cpp test_main.cpp promise.cpp with.cpp op.cpp handler.cpp join.cpp race.cpp this_coro.cpp
channel.cpp generator.cpp run.cpp task.cpp gather.cpp wait_group.cpp wrappers.cpp left_race.cpp
strand.cpp fork.cpp thread.cpp any_completion_handler.cpp detached.cpp monotonic_resource.cpp sbo_resource.cpp)

View File

@@ -1,149 +0,0 @@
// Copyright (c) 2023 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/cobalt/leaf.hpp>
#include <boost/cobalt/promise.hpp>
#include <boost/leaf/result.hpp>
#include <boost/test/unit_test.hpp>
#include "test.hpp"
using namespace boost;
BOOST_AUTO_TEST_SUITE(leaf_);
CO_TEST_CASE(try_catch)
{
BOOST_CHECK(co_await cobalt::try_catch(
[]() -> cobalt::promise<int>
{
throw std::runtime_error("TestException");
co_return 42;
}(),
[](std::runtime_error & re)
{
BOOST_CHECK(re.what() == std::string("TestException"));
return -1;
},
[](std::exception &)
{
BOOST_CHECK(false);
return -2;
}) == -1);
BOOST_CHECK(co_await cobalt::try_catch(
[]() -> cobalt::promise<int>
{
co_return 42;
}(),
[](std::runtime_error &)
{
BOOST_CHECK(false);
return -1;
},
[](std::exception &)
{
BOOST_CHECK(false);
return -2;
}) == 42);
}
CO_TEST_CASE(try_handle_all)
{
BOOST_CHECK(co_await cobalt::try_handle_all(
[]() -> cobalt::promise<leaf::result<int>>
{
throw std::runtime_error("TestException");
co_return 42;
}(),
[](const std::runtime_error & re)
{
BOOST_CHECK(re.what() == std::string("TestException"));
return -1;
},
[](const std::exception &)
{
BOOST_CHECK(false);
return -2;
},
[]
{
BOOST_CHECK(false);
return -3;
}) == -1);
BOOST_CHECK(co_await cobalt::try_handle_all(
[]() -> cobalt::promise<leaf::result<int>>
{
co_return 42;
}(),
[](const std::runtime_error &)
{
BOOST_CHECK(false);
return -1;
},
[](const std::exception &)
{
BOOST_CHECK(false);
return -2;
},
[]
{
BOOST_CHECK(false);
return -3;
}) == 42);
}
CO_TEST_CASE(try_handle_all_)
{
BOOST_CHECK((co_await cobalt::try_handle_some(
[]() -> cobalt::promise<leaf::result<int>>
{
throw std::runtime_error("TestException");
co_return 42;
}(),
[](const std::runtime_error & re)
{
BOOST_CHECK(re.what() == std::string("TestException"));
return -1;
},
[](const std::exception &)
{
BOOST_CHECK(false);
return -2;
},
[]
{
BOOST_CHECK(false);
return -3;
})).value() == -1);
BOOST_CHECK((co_await cobalt::try_handle_some(
[]() -> cobalt::promise<leaf::result<int>>
{
co_return 42;
}(),
[](const std::runtime_error &)
{
BOOST_CHECK(false);
return -1;
},
[](const std::exception &)
{
BOOST_CHECK(false);
return -2;
},
[]
{
BOOST_CHECK(false);
return -3;
})).value() == 42);
}
BOOST_AUTO_TEST_SUITE_END();