Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Oct 16, 2023
1 parent 6693c89 commit 2a50293
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/test_coro_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,26 @@ TEST_CASE("coro_server example, will block") {
server.set_http_handler<cinatra::GET, cinatra::POST>(
"/", [](coro_http_request &req, coro_http_response &resp) {
// response in io thread.
std::this_thread::sleep_for(10ms);
resp.set_status_and_content(cinatra::status_type::ok, "hello world");
});

server.set_http_handler<cinatra::GET>(
"/coro",
[](coro_http_request &req,
coro_http_response &resp) -> async_simple::coro::Lazy<void> {
co_await coro_io::post([&] {
co_await coro_io::post([&]() {
// coroutine in other thread.
std::this_thread::sleep_for(10ms);
resp.set_status_and_content(cinatra::status_type::ok, "hello world");
});
co_return;
});

server.set_http_handler<cinatra::GET, cinatra::POST>(
"/echo", [](coro_http_request &req, coro_http_response &resp) {
// response in io thread.
resp.set_status_and_content(cinatra::status_type::ok, "hello world");
});
server.sync_start();
CHECK(server.port() > 0);
Expand Down

0 comments on commit 2a50293

Please sign in to comment.