Python exceptions can now be handled via QML
callCoro/callBackendCoro can now take onSuccess(result) and onError(type, args, errorObject) callbacks.
This commit is contained in:
@@ -61,9 +61,17 @@ class App:
|
||||
|
||||
|
||||
def _call_coro(self, coro: Coroutine, uuid: str) -> None:
|
||||
self.run_in_loop(coro).add_done_callback(
|
||||
lambda future: CoroutineDone(uuid=uuid, result=future.result()),
|
||||
)
|
||||
def on_done(future: Future) -> None:
|
||||
try:
|
||||
result = future.result()
|
||||
exception = None
|
||||
except Exception as err:
|
||||
result = None
|
||||
exception = err
|
||||
|
||||
CoroutineDone(uuid, result, exception)
|
||||
|
||||
self.run_in_loop(coro).add_done_callback(on_done)
|
||||
|
||||
|
||||
def call_backend_coro(self, name: str, uuid: str, args: Sequence[str] = (),
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, List, Union
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
import pyotherside
|
||||
|
||||
@@ -47,8 +47,9 @@ class AlertRequested(PyOtherSideEvent):
|
||||
class CoroutineDone(PyOtherSideEvent):
|
||||
"""Indicate that an asyncio coroutine finished."""
|
||||
|
||||
uuid: str = field()
|
||||
result: Any = None
|
||||
uuid: str = field()
|
||||
result: Any = None
|
||||
exception: Optional[Exception] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
Reference in New Issue
Block a user