Force server methods to be async and client calls to use await

This commit is contained in:
Lasse Blaauwbroek
2023-06-08 03:56:57 +02:00
parent a69bc72a0b
commit 4b5c4211f1
11 changed files with 193 additions and 310 deletions

View File

@@ -5,7 +5,7 @@ class FooServer(test_response_capnp.Foo.Server):
def __init__(self, val=1):
self.val = val
def foo(self, **kwargs):
async def foo(self, **kwargs):
return 1
@@ -13,27 +13,27 @@ class BazServer(test_response_capnp.Baz.Server):
def __init__(self, val=1):
self.val = val
def grault(self, **kwargs):
async def grault(self, **kwargs):
return {"foo": FooServer()}
async def test_response_reference():
baz = test_response_capnp.Baz._new_client(BazServer())
bar = baz.grault().wait().bar
bar = (await baz.grault()).bar
foo = bar.foo
# This used to cause an exception about invalid pointers because the response got garbage collected
assert foo.foo().wait().val == 1
assert (await foo.foo()).val == 1
async def test_response_reference2():
baz = test_response_capnp.Baz._new_client(BazServer())
bar = baz.grault().wait().bar
bar = (await baz.grault()).bar
# This always worked since it saved the intermediate response object
response = baz.grault().wait()
response = await baz.grault()
bar = response.bar
foo = bar.foo
assert foo.foo().wait().val == 1
assert (await foo.foo()).val == 1