handle check task being cancelled while view is shown

This commit is contained in:
Michael Hudson-Doyle 2019-12-16 12:41:43 +13:00
parent de18cc977f
commit 394cfc723c
2 changed files with 13 additions and 7 deletions

View File

@ -65,9 +65,7 @@ class RefreshController(BaseController):
@property
def check_state(self):
task = self.check_task.task
if not task.done():
return CheckState.UNKNOWN
if task.cancelled():
if not task.done() or task.cancelled():
return CheckState.UNKNOWN
if task.exception():
return CheckState.UNAVAILABLE

View File

@ -163,10 +163,18 @@ class RefreshView(BaseView):
schedule_task(self._wait_check_result())
async def _wait_check_result(self):
while True:
try:
check_state = await self.controller.check_task.task
except asyncio.CancelledError:
# If the task was cancelled, another will have been
# started.
continue
except Exception as e:
self.check_state_failed(e)
return
else:
break
if check_state == CheckState.AVAILABLE:
self.check_state_available()
else: