Blame external/pybind11/tests/test_async.cpp
|
Packit |
534379 |
/*
|
|
Packit |
534379 |
tests/test_async.cpp -- __await__ support
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Copyright (c) 2019 Google Inc.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
All rights reserved. Use of this source code is governed by a
|
|
Packit |
534379 |
BSD-style license that can be found in the LICENSE file.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include "pybind11_tests.h"
|
|
Packit |
534379 |
|
|
Packit |
534379 |
TEST_SUBMODULE(async_module, m) {
|
|
Packit |
534379 |
struct DoesNotSupportAsync {};
|
|
Packit |
534379 |
py::class_<DoesNotSupportAsync>(m, "DoesNotSupportAsync")
|
|
Packit |
534379 |
.def(py::init<>());
|
|
Packit |
534379 |
struct SupportsAsync {};
|
|
Packit |
534379 |
py::class_<SupportsAsync>(m, "SupportsAsync")
|
|
Packit |
534379 |
.def(py::init<>())
|
|
Packit |
534379 |
.def("__await__", [](const SupportsAsync& self) -> py::object {
|
|
Packit |
534379 |
static_cast<void>(self);
|
|
Packit |
534379 |
py::object loop = py::module::import("asyncio.events").attr("get_event_loop")();
|
|
Packit |
534379 |
py::object f = loop.attr("create_future")();
|
|
Packit |
534379 |
f.attr("set_result")(5);
|
|
Packit |
534379 |
return f.attr("__await__")();
|
|
Packit |
534379 |
});
|
|
Packit |
534379 |
}
|