Reduce latency to set up websocket forwarding in hassio (#111558)

Reduce latancy to set up websocket forwarding in hassio

Create the tasks eagerly to avoid one iteration of the event loop
to connect the proxy
This commit is contained in:
J. Nick Koston 2024-02-26 15:52:37 -10:00 committed by GitHub
parent ae2ce99cbd
commit 321295a872
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,6 +18,7 @@ from homeassistant.components.http import HomeAssistantView
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import UNDEFINED from homeassistant.helpers.typing import UNDEFINED
from homeassistant.util.async_ import create_eager_task
from .const import X_HASS_SOURCE, X_INGRESS_PATH from .const import X_HASS_SOURCE, X_INGRESS_PATH
from .http import should_compress from .http import should_compress
@ -143,8 +144,8 @@ class HassIOIngress(HomeAssistantView):
# Proxy requests # Proxy requests
await asyncio.wait( await asyncio.wait(
[ [
asyncio.create_task(_websocket_forward(ws_server, ws_client)), create_eager_task(_websocket_forward(ws_server, ws_client)),
asyncio.create_task(_websocket_forward(ws_client, ws_server)), create_eager_task(_websocket_forward(ws_client, ws_server)),
], ],
return_when=asyncio.FIRST_COMPLETED, return_when=asyncio.FIRST_COMPLETED,
) )