Skip to content
Snippets Groups Projects

Async guard

Merged Mateusz Żebrak requested to merge mzebrak/async-guard into develop
All threads resolved!
3 files
+ 34
31
Compare changes
  • Side-by-side
  • Inline
Files
3
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
@@ -10,10 +9,6 @@ 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()
@@ -33,24 +28,24 @@ class CreateProfileForm(Form):
# so this method won't be called
async def impl() -> None:
with self._async_guard:
with self.app._going_into_unlocked_mode_guard:
await self.app.switch_mode("unlock")
await self.app.remove_mode("create_profile")
if self._async_guard.is_available:
if self.app._going_into_unlocked_mode_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 impl() -> None:
with self._async_guard:
with self.app._going_into_unlocked_mode_guard:
await self.execute_post_actions()
self.profile.enable_saving()
await self.commands.save_profile()
await self.app._switch_mode_into_unlocked()
if self._async_guard.is_available:
if self.app._going_into_unlocked_mode_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