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 @property
def check_state(self): def check_state(self):
task = self.check_task.task task = self.check_task.task
if not task.done(): if not task.done() or task.cancelled():
return CheckState.UNKNOWN
if task.cancelled():
return CheckState.UNKNOWN return CheckState.UNKNOWN
if task.exception(): if task.exception():
return CheckState.UNAVAILABLE return CheckState.UNAVAILABLE

View File

@ -163,10 +163,18 @@ class RefreshView(BaseView):
schedule_task(self._wait_check_result()) schedule_task(self._wait_check_result())
async def _wait_check_result(self): async def _wait_check_result(self):
try: while True:
check_state = await self.controller.check_task.task try:
except Exception as e: check_state = await self.controller.check_task.task
self.check_state_failed(e) 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: if check_state == CheckState.AVAILABLE:
self.check_state_available() self.check_state_available()
else: else: