MCPcopy Create free account
hub / github.com/alibaba/yalantinglibs / async_get

Function async_get

src/coro_http/examples/py_example/py_example.cpp:35–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33};
34
35pybind11::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
62PYBIND11_MODULE(py_example, m) {
63 m.def("hello", [] {

Callers

nothing calls this directly

Calls 5

createFunction · 0.85
make_tupleFunction · 0.85
startMethod · 0.45
send_requestMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected