-
-
Save rickwierenga/b67ddcbc41b8469ab2dcf29f90d245d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LH: | |
| def __init__(self, *args, **kwargs): | |
| self.handlers = [] | |
| async def actual_method(self, parameter): | |
| try: | |
| print(parameter) | |
| if parameter == "wrong input": | |
| raise ValueError | |
| except Exception as error: | |
| await self.handlers[0](self.actual_method, error, parameter) | |
| async def handler(self, awaitable, handler): | |
| self.handlers.append(handler) | |
| await awaitable | |
| self.handlers = [] | |
| async def main(): | |
| async def handler(function, error, parameter): | |
| await function(parameter="good input") | |
| lh = LH() | |
| await lh.handler(lh.actual_method(parameter="wrong input"), handler) | |
| import asyncio | |
| asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment