| 10 | #include "pybind11_tests.h" |
| 11 | |
| 12 | TEST_SUBMODULE(async_module, m) { |
| 13 | struct DoesNotSupportAsync {}; |
| 14 | py::class_<DoesNotSupportAsync>(m, "DoesNotSupportAsync").def(py::init<>()); |
| 15 | struct SupportsAsync {}; |
| 16 | py::class_<SupportsAsync>(m, "SupportsAsync") |
| 17 | .def(py::init<>()) |
| 18 | .def("__await__", [](const SupportsAsync &self) -> py::object { |
| 19 | static_cast<void>(self); |
| 20 | py::object loop = py::module_::import("asyncio.events").attr("get_event_loop")(); |
| 21 | py::object f = loop.attr("create_future")(); |
| 22 | f.attr("set_result")(5); |
| 23 | return f.attr("__await__")(); |
| 24 | }); |
| 25 | } |