diff --git a/Week05/awaitme_aycaselda_keskin.py b/Week05/awaitme_aycaselda_keskin.py new file mode 100644 index 00000000..c5ed98f9 --- /dev/null +++ b/Week05/awaitme_aycaselda_keskin.py @@ -0,0 +1,19 @@ +import asyncio +from functools import wraps + +def awaitme(fn): + """A decorator that turns any function into a coroutine.""" + + if asyncio.iscoroutinefunction(fn): + return fn + + @wraps(fn) + async def wrapper(*args, **kwargs): + result = fn(*args, **kwargs) + + if asyncio.iscoroutine(result): + return await result + + return result + + return wrapper