Skip to content

Commit

Permalink
[no ci]fix doc (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Jan 16, 2024
1 parent 77402b6 commit 3448ac0
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lang/coro_http_client_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,21 +504,23 @@ client 不是线程安全的,要确保只有一个线程在调用client,如

方式二:

通过多个协程去请求服务端
通过多个协程去请求服务端, 每个协程都在内部线程池的某个线程中执行。去请求服务端

```c++
coro_http_client client;
std::vector<async_simple::coro::Lazy<resp_data>> futures;
for (int i = 0; i < 10; ++i) {
futures.push_back(client.async_get("http://www.baidu.com/"));
}
std::vector<std::shared_ptr<coro_http_client>> clients;
std::vector<async_simple::coro::Lazy<resp_data>> futures;
for (int i = 0; i < 10; ++i) {
auto client = std::make_shared<coro_http_client>();
futures.push_back(client->async_get("http://www.baidu.com/"));
clients.push_back(client);
}

auto out = co_await async_simple::coro::collectAll(std::move(futures));
auto out = co_await async_simple::coro::collectAll(std::move(futures));

for (auto &item : out) {
auto result = item.value();
CHECK(result.status == 200);
}
for (auto &item : out) {
auto result = item.value();
assert(result.status == 200);
}
```
# 设置解析http response 的最大header 数量
Expand Down

0 comments on commit 3448ac0

Please sign in to comment.