Skip to content

Commit 71731f5

Browse files
committed
OP#8343:
Extract helper function
1 parent efef672 commit 71731f5

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎OTAnalytics/plugin_ui/nicegui_gui/pages/sections_and_flow_form/flow_form.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import asyncio
21
from typing import Iterable, Self
32

43
from nicegui import ui
54
from nicegui.elements.button import Button
65
from nicegui.events import ClickEventArguments
6+
from plugin_ui.utils.asyncio_helper import run_async
77

88
from OTAnalytics.adapter_ui.abstract_frame import AbstractFrame
99
from OTAnalytics.adapter_ui.abstract_treeview_interface import AbstractTreeviewInterface
@@ -109,7 +109,7 @@ def generate_flow(self) -> None:
109109
self._viewmodel.generate_flows()
110110

111111
def remove_flow(self) -> None:
112-
asyncio.create_task(self._viewmodel.remove_flows())
112+
run_async(self._viewmodel.remove_flows())
113113

114114
async def show_flow_properties(self) -> None:
115115
await self._viewmodel.edit_selected_flow()

‎OTAnalytics/plugin_ui/nicegui_gui/pages/sections_and_flow_form/sections_form.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import asyncio
21
from typing import Any, Iterable, Self
32

43
from nicegui import ui
54
from nicegui.elements.button import Button
5+
from plugin_ui.utils.asyncio_helper import run_async
66

77
from OTAnalytics.adapter_ui.abstract_treeview_interface import AbstractTreeviewInterface
88
from OTAnalytics.adapter_ui.view_model import ViewModel
@@ -140,7 +140,7 @@ def update_selected_items(self, item_ids: list[str]) -> None:
140140
self._section_table.select(item_ids)
141141

142142
def remove_sections(self) -> None:
143-
asyncio.create_task(self._viewmodel.remove_sections())
143+
run_async(self._viewmodel.remove_sections())
144144

145145
def update_items(self) -> None:
146146
self._section_table.update(map_to_ui(self._viewmodel.get_all_sections()))

‎OTAnalytics/plugin_ui/utils/__init__.py‎

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import asyncio
2+
from typing import Coroutine
3+
4+
5+
def run_async(coro: Coroutine) -> None:
6+
# Schedule the asynchronous removal so tests see the call immediately
7+
# while NiceGUI executes the coroutine in the event loop.
8+
try:
9+
asyncio.create_task(coro)
10+
except RuntimeError:
11+
# No running loop available; run the coroutine to completion
12+
asyncio.run(coro)

0 commit comments

Comments
 (0)