Migrate async_run_job to use eager_start for tasks (#113011)
parent
52b69bcfde
commit
77cdecf0f1
|
@ -855,7 +855,7 @@ class HomeAssistant:
|
|||
# https://github.com/home-assistant/core/pull/71960
|
||||
if TYPE_CHECKING:
|
||||
target = cast(Callable[..., Coroutine[Any, Any, _R] | _R], target)
|
||||
return self.async_run_hass_job(HassJob(target), *args)
|
||||
return self.async_run_hass_job(HassJob(target), *args, eager_start=True)
|
||||
|
||||
def block_till_done(self) -> None:
|
||||
"""Block until all pending work is done."""
|
||||
|
|
|
@ -2116,6 +2116,20 @@ async def test_async_functions_with_callback(hass: HomeAssistant) -> None:
|
|||
assert len(runs) == 3
|
||||
|
||||
|
||||
async def test_async_run_job_starts_tasks_eagerly(hass: HomeAssistant) -> None:
|
||||
"""Test async_run_job starts tasks eagerly."""
|
||||
runs = []
|
||||
|
||||
async def _test():
|
||||
runs.append(True)
|
||||
|
||||
task = hass.async_run_job(_test)
|
||||
# No call to hass.async_block_till_done to ensure the task is run eagerly
|
||||
assert len(runs) == 1
|
||||
assert task.done()
|
||||
await task
|
||||
|
||||
|
||||
def test_valid_entity_id() -> None:
|
||||
"""Test valid entity ID."""
|
||||
for invalid in [
|
||||
|
|
Loading…
Reference in New Issue