diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index e47113f..02ba3f4 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -2241,7 +2241,8 @@ cdef class TwoPartyServer: return _CapabilityClient()._init(helpers.bootstrapHelperServer(deref(self.thisptr)), self) cpdef on_disconnect(self) except +reraise_kj_exception: - return self._network.on_disconnect() + return _voidpromise_to_asyncio(deref(self._network.thisptr).onDisconnect() + .attach(capnp.heap[PyRefCounter](self))) cdef class _AsyncIoStream: diff --git a/examples/async_calculator_server.py b/examples/async_calculator_server.py index 221180a..f8302c3 100755 --- a/examples/async_calculator_server.py +++ b/examples/async_calculator_server.py @@ -110,8 +110,7 @@ class CalculatorImpl(calculator_capnp.Calculator.Server): async def new_connection(stream): - server = capnp.TwoPartyServer(stream, bootstrap=CalculatorImpl()) - await server.on_disconnect() + await capnp.TwoPartyServer(stream, bootstrap=CalculatorImpl()).on_disconnect() def parse_args(): diff --git a/examples/async_server.py b/examples/async_server.py index 3230bd3..5d5b63d 100755 --- a/examples/async_server.py +++ b/examples/async_server.py @@ -25,8 +25,7 @@ class ExampleImpl(thread_capnp.Example.Server): async def new_connection(stream): - server = capnp.TwoPartyServer(stream, bootstrap=ExampleImpl()) - await server.on_disconnect() + await capnp.TwoPartyServer(stream, bootstrap=ExampleImpl()).on_disconnect() def parse_args(): diff --git a/examples/async_ssl_calculator_server.py b/examples/async_ssl_calculator_server.py index cfeb1cc..8657d72 100755 --- a/examples/async_ssl_calculator_server.py +++ b/examples/async_ssl_calculator_server.py @@ -125,8 +125,7 @@ def parse_args(): async def new_connection(stream): - server = capnp.TwoPartyServer(stream, bootstrap=CalculatorImpl()) - await server.on_disconnect() + await capnp.TwoPartyServer(stream, bootstrap=CalculatorImpl()).on_disconnect() async def main(): diff --git a/examples/async_ssl_server.py b/examples/async_ssl_server.py index e404be9..9d629a5 100755 --- a/examples/async_ssl_server.py +++ b/examples/async_ssl_server.py @@ -33,8 +33,7 @@ class ExampleImpl(thread_capnp.Example.Server): async def new_connection(stream): - server = capnp.TwoPartyServer(stream, bootstrap=ExampleImpl()) - await server.on_disconnect() + await capnp.TwoPartyServer(stream, bootstrap=ExampleImpl()).on_disconnect() def parse_args():