Skip to content
Snippets Groups Projects

Async guard

Merged Mateusz Żebrak requested to merge mzebrak/async-guard into develop
1 file
+ 33
13
Compare changes
  • Side-by-side
  • Inline
from __future__ import annotations
from clive.__private.core.async_guard import AsyncGuard
from clive.__private.core.profile import Profile
from clive.__private.ui.forms.create_profile.new_key_alias_form_screen import NewKeyAliasFormScreen
from clive.__private.ui.forms.create_profile.profile_credentials_form_screen import ProfileCredentialsFormScreen
@@ -9,6 +10,10 @@ from clive.__private.ui.forms.form import ComposeFormResult, Form
class CreateProfileForm(Form):
def __init__(self) -> None:
super().__init__()
self._async_guard = AsyncGuard()
async def initialize(self) -> None:
await self.world.create_new_profile("temp_name")
self.profile.skip_saving()
@@ -26,20 +31,35 @@ class CreateProfileForm(Form):
async def exit_form(self) -> None:
# when this form is displayed during onboarding, there is no previous screen to go back to
# so this method won't be called
await self.app.switch_mode("unlock")
self.app.remove_mode("create_profile")
async def impl() -> None:
with self._async_guard:
await self.app.switch_mode("unlock")
await self.app.remove_mode("create_profile")
if self._async_guard.is_available:
# Has to be done in a separate task to avoid deadlock.
# More: https://github.com/Textualize/textual/issues/5008
self.app.run_worker(impl())
async def finish_form(self) -> None:
async def handle_modes() -> None:
await self.app.switch_mode("dashboard")
self.app.remove_mode("create_profile")
self.app.remove_mode("unlock")
self.add_post_action(
lambda: self.app.update_alarms_data_on_newest_node_data(suppress_cancelled_error=True),
self.app.resume_refresh_alarms_data_interval,
)
await self.execute_post_actions()
await handle_modes()
self.profile.enable_saving()
await self.commands.save_profile()
await self.app.remove_mode("create_profile")
await self.app.remove_mode("unlock")
async def impl() -> None:
with self._async_guard:
self.add_post_action(
lambda: self.app.update_alarms_data_on_newest_node_data(suppress_cancelled_error=True),
self.app.resume_refresh_alarms_data_interval,
)
await self.execute_post_actions()
await handle_modes()
self.profile.enable_saving()
await self.commands.save_profile()
if self._async_guard.is_available:
# Has to be done in a separate task to avoid deadlock.
# More: https://github.com/Textualize/textual/issues/5008
self.app.run_worker(impl())
Loading