Migrate rest to use eager tasks for setup (#112166)

The refresh tasks will avoid one iteration of the event loop
to start fetching data

The load tasks will likely never suspend and avoid being
scheduled on the event loop
This commit is contained in:
J. Nick Koston 2024-03-04 01:26:55 -10:00 committed by GitHub
parent 613bf1c226
commit a698bd5800
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,6 +40,7 @@ from homeassistant.helpers.reload import (
)
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.util.async_ import create_eager_task
from .const import (
CONF_ENCODING,
@ -129,10 +130,10 @@ async def _async_process_config(hass: HomeAssistant, config: ConfigType) -> bool
load_coroutines.append(load_coroutine)
if refresh_coroutines:
await asyncio.gather(*refresh_coroutines)
await asyncio.gather(*(create_eager_task(coro) for coro in refresh_coroutines))
if load_coroutines:
await asyncio.gather(*load_coroutines)
await asyncio.gather(*(create_eager_task(coro) for coro in load_coroutines))
return True