Skip to content

Commit

Permalink
Refactor event handling in EventHandler class
Browse files Browse the repository at this point in the history
  • Loading branch information
Garulf committed Feb 16, 2024
1 parent 89e784e commit a829da2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pyflowlauncher/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def add_events(self, events: Iterable[Callable[..., Any]]):
def add_exception_handler(self, exception: Type[Exception], handler: Callable[..., Any]):
self._handlers[exception] = handler

def _call_event(self, event: str, *args, **kwargs) -> Callable[..., Any] | None:
return self._events[event](*args, **kwargs)
def get_event(self, event: str) -> Callable[..., Any]:
return self._events[event]

async def _await_maybe(self, result: Any) -> Any:
if asyncio.iscoroutine(result):
Expand All @@ -33,7 +33,7 @@ async def _await_maybe(self, result: Any) -> Any:

async def trigger_event(self, event: str, *args, **kwargs) -> Any:
try:
result = self._call_event(event, *args, **kwargs)
result = self.get_event(event)(*args, **kwargs)
return await self._await_maybe(result)
except Exception as e:
handler = self._handlers.get(type(e), None)
Expand Down

0 comments on commit a829da2

Please sign in to comment.