Skip to content

Commit fff4117

Browse files
committed
CRAI: improve remaining tasks cancellation
1 parent 688014f commit fff4117

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,13 @@ async def get_missing_energy_logs(self) -> None:
502502
create_task(self.energy_log_update(address))
503503
for address in missing_addresses
504504
]
505-
for task in tasks:
506-
await task
507-
# When an energy log collection task returns False, do not execute the remaining tasks
508-
if not task.result():
509-
for t in tasks:
505+
for idx, task in enumerate(tasks):
506+
result = await task
507+
# When an energy log collection task returns False, stop and cancel the remaining tasks
508+
if not result:
509+
for t in tasks[idx + 1 :]:
510510
t.cancel()
511+
break
511512

512513
if self._cache_enabled:
513514
await self._energy_log_records_save_to_cache()

0 commit comments

Comments
 (0)