Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:51

0001 /*
0002     tests/test_async.cpp -- __await__ support
0003 
0004     Copyright (c) 2019 Google Inc.
0005 
0006     All rights reserved. Use of this source code is governed by a
0007     BSD-style license that can be found in the LICENSE file.
0008 */
0009 
0010 #include "pybind11_tests.h"
0011 
0012 TEST_SUBMODULE(async_module, m) {
0013     struct DoesNotSupportAsync {};
0014     py::class_<DoesNotSupportAsync>(m, "DoesNotSupportAsync").def(py::init<>());
0015     struct SupportsAsync {};
0016     py::class_<SupportsAsync>(m, "SupportsAsync")
0017         .def(py::init<>())
0018         .def("__await__", [](const SupportsAsync &self) -> py::object {
0019             static_cast<void>(self);
0020             py::object loop = py::module_::import("asyncio.events").attr("get_event_loop")();
0021             py::object f = loop.attr("create_future")();
0022             f.attr("set_result")(5);
0023             return f.attr("__await__")();
0024         });
0025 }