Skip to content

Instantly share code, notes, and snippets.

@mturoci
Created September 20, 2022 16:10
Show Gist options
  • Save mturoci/91bb046f393a5a4d5ea48494ff42a20d to your computer and use it in GitHub Desktop.
Save mturoci/91bb046f393a5a4d5ea48494ff42a20d to your computer and use it in GitHub Desktop.
# Start the polling, wrap in future so that we can cancel it later.
q.client.future = asyncio.ensure_future(polling_function(q))
# Future cancellation raises an error - use trycatch.
try:
# Wait until polling finished.
await q.client.future
q.page['meta'].dialog = None
q.page['meta'].notification_bar = ui.notification_bar(
name='success_notification',
text='Job done!',
type='success',
events=['dismissed']
)
# Handle cancellation.
except asyncio.CancelledError:
q.page['meta'].dialog.items[0].progress.caption = 'Cancelled'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment