μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
test_async.cpp
Go to the documentation of this file.
1/*
2 tests/test_async.cpp -- __await__ support
3
4 Copyright (c) 2019 Google Inc.
5
6 All rights reserved. Use of this source code is governed by a
7 BSD-style license that can be found in the LICENSE file.
8*/
9
10#include "pybind11_tests.h"
11
12TEST_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}
static const self_t self
Definition: operators.h:72
#define TEST_SUBMODULE(name, variable)