Skip to content

Instantly share code, notes, and snippets.

@napsternxg
Created June 15, 2023 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save napsternxg/0c08c32027b059a63fc95fc577dd26bd to your computer and use it in GitHub Desktop.
Save napsternxg/0c08c32027b059a63fc95fc577dd26bd to your computer and use it in GitHub Desktop.
Async Decorator
import asyncio
def async_decorator(acreate_fn):
async def _f(*args, **kwargs):
print(f"Decorated fn: {args=}, {kwargs=}. Sleeping.")
await asyncio.sleep(0.1)
return await acreate_fn(*args, **kwargs)
return _f
@async_decorator
async def some_func(i):
print(f"Regular fn: {i=}")
return i
print(asyncio.run(some_func(10)))
"""
Decorated fn: args=(10,), kwargs={}. Sleeping.
Regular fn: i=10
10
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment