nxbt/nxbt/controller/async_server.py

31 lines
1,019 B
Python

import asyncio
from .server import ControllerServer
class AsyncControllerServer:
"""Async facade for the legacy ControllerServer.
This wrapper allows higher-level asyncio code to await controller
lifecycle operations while the underlying implementation continues
to use blocking sockets and multiprocessing primitives.
"""
def __init__(self, *args, **kwargs):
self._server = ControllerServer(*args, **kwargs)
async def run(self, reconnect_address=None):
return await self._server.run_async(reconnect_address)
async def save_connection(self, error, state=None):
return await self._server.save_connection_async(error, state)
async def connect(self):
return await self._server.connect_async()
async def reconnect(self, reconnect_address):
return await self._server.reconnect_async(reconnect_address)
async def stop(self):
loop = asyncio.get_running_loop()
await loop.run_in_executor(None, self._server._on_exit)