Skip to content

Instantly share code, notes, and snippets.

@rickwierenga
Last active May 29, 2025 20:20
Show Gist options
  • Select an option

  • Save rickwierenga/b67ddcbc41b8469ab2dcf29f90d245d3 to your computer and use it in GitHub Desktop.

Select an option

Save rickwierenga/b67ddcbc41b8469ab2dcf29f90d245d3 to your computer and use it in GitHub Desktop.
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