Skip to content

Commit

Permalink
rename coro_channel to channel
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Aug 5, 2024
1 parent e506614 commit ad84818
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
11 changes: 5 additions & 6 deletions include/ylt/coro_io/coro_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,11 @@ post(Func func,
}

template <typename R>
struct coro_channel
: public asio::experimental::channel<void(std::error_code, R)> {
struct channel : public asio::experimental::channel<void(std::error_code, R)> {
using return_type = R;
using ValueType = std::pair<std::error_code, R>;
using asio::experimental::channel<void(std::error_code, R)>::channel;
coro_channel(coro_io::ExecutorWrapper<> *executor, size_t capacity)
channel(coro_io::ExecutorWrapper<> *executor, size_t capacity)
: executor_(executor),
asio::experimental::channel<void(std::error_code, R)>(
executor->get_asio_executor(), capacity) {}
Expand All @@ -380,17 +379,17 @@ struct coro_channel
};

template <typename R>
inline coro_channel<R> create_load_blancer(
inline channel<R> create_load_blancer(
size_t capacity,
coro_io::ExecutorWrapper<> *executor = coro_io::get_global_executor()) {
return coro_channel<R>(executor, capacity);
return channel<R>(executor, capacity);
}

template <typename R>
inline auto create_shared_channel(
size_t capacity,
coro_io::ExecutorWrapper<> *executor = coro_io::get_global_executor()) {
return std::make_shared<coro_channel<R>>(executor, capacity);
return std::make_shared<channel<R>>(executor, capacity);
}

template <typename T>
Expand Down
3 changes: 1 addition & 2 deletions src/coro_http/examples/load_blancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ int main() {
std::vector<std::string_view> hosts{"http://baidu.com",
"http://www.baidu.com"};
auto chan = coro_io::load_blancer<coro_http_client>::create(
hosts, coro_io::load_blancer<coro_http_client>::load_blancer_config{
.pool_config{.max_connection = 100}});
hosts, {.pool_config{.max_connection = 100}});

for (int i = 0, lim = std::thread::hardware_concurrency(); i < lim; ++i)
test_async_load_blancer(chan).start([](auto &&) {
Expand Down
4 changes: 2 additions & 2 deletions src/coro_io/tests/test_coro_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace std::chrono_literals;
#define IS_OK
#endif

async_simple::coro::Lazy<void> test_coro_channel() {
async_simple::coro::Lazy<void> test_channel() {
auto ch = coro_io::create_load_blancer<int>(1000);

co_await coro_io::async_send(ch, 41);
Expand Down Expand Up @@ -162,7 +162,7 @@ void callback_lazy() {
}

TEST_CASE("test channel send recieve, test select channel and coroutine") {
async_simple::coro::syncAwait(test_coro_channel());
async_simple::coro::syncAwait(test_channel());
async_simple::coro::syncAwait(test_select_channel());
callback_lazy();
}
3 changes: 1 addition & 2 deletions src/coro_rpc/examples/base_examples/load_blancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ int main() {
std::vector<std::string_view>{"127.0.0.1:8801", "localhost:8801"};
auto worker_cnt = std::thread::hardware_concurrency() * 20;
auto chan = coro_io::load_blancer<coro_rpc_client>::create(
hosts, coro_io::load_blancer<coro_rpc_client>::load_blancer_config{
.pool_config{.max_connection = worker_cnt}});
hosts, {.pool_config{.max_connection = worker_cnt}});
auto chan_ptr = std::make_shared<decltype(chan)>(std::move(chan));
auto executor = coro_io::get_global_block_executor();
for (int i = 0; i < worker_cnt; ++i) {
Expand Down

0 comments on commit ad84818

Please sign in to comment.