Scarab
v2.11.1
Project 8 C++ Utility Library
library
external
pybind11
tests
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
12
TEST_SUBMODULE
(
async_module
, m) {
13
struct
DoesNotSupportAsync {};
14
py::class_<DoesNotSupportAsync>
(m,
"DoesNotSupportAsync"
)
15
.def(py::init<>());
16
struct
SupportsAsync {};
17
py::class_<SupportsAsync>
(m,
"SupportsAsync"
)
18
.def(py::init<>())
19
.def(
"__await__"
, [](
const
SupportsAsync&
self
) ->
py::object
{
20
static_cast<
void
>
(
self
);
21
py::object
loop = py::module::import(
"asyncio.events"
).
attr
(
"get_event_loop"
)();
22
py::object
f = loop.
attr
(
"create_future"
)();
23
f.
attr
(
"set_result"
)(5);
24
return
f.
attr
(
"__await__"
)();
25
});
26
}
pybind11_tests.h
pybind11::class_
Definition:
pybind11.h:1038
pybind11::object
Definition:
pytypes.h:230
pybind11::detail::object_api::attr
obj_attr_accessor attr(handle key) const
Definition:
pytypes.h:1410
TEST_SUBMODULE
#define TEST_SUBMODULE(name, variable)
Definition:
pybind11_tests.h:20
async_module
test_initializer async_module("async_module", test_submodule_async_module)
Generated by
1.8.13