| 33 | }; |
| 34 | |
| 35 | pybind11::object async_get(py::handle loop, std::string url, py::buffer buf) { |
| 36 | auto local_future = loop.attr("create_future")(); |
| 37 | py::handle future = local_future; |
| 38 | |
| 39 | py::buffer_info info = buf.request(true); |
| 40 | char *data = static_cast<char *>(info.ptr); |
| 41 | std::span<char> out_buf(data, info.size); |
| 42 | |
| 43 | static auto pool = |
| 44 | coro_io::client_pool<coro_http::coro_http_client>::create(url); |
| 45 | pool->send_request( |
| 46 | [url, loop, future, out_buf](coro_http::coro_http_client &client) |
| 47 | -> async_simple::coro::Lazy<void> { |
| 48 | coro_http::req_context<> ctx{}; |
| 49 | auto result = co_await client.async_request( |
| 50 | std::move(url), coro_http::http_method::GET, std::move(ctx), {}, |
| 51 | out_buf); |
| 52 | py::gil_scoped_acquire acquire; |
| 53 | loop.attr("call_soon_threadsafe")( |
| 54 | future.attr("set_result"), |
| 55 | py::make_tuple(!result.net_err, result.resp_body.size())); |
| 56 | }) |
| 57 | .start([](auto &&) { |
| 58 | }); |
| 59 | return local_future; |
| 60 | } |
| 61 | |
| 62 | PYBIND11_MODULE(py_example, m) { |
| 63 | m.def("hello", [] { |
nothing calls this directly
no test coverage detected