diff --git a/Week05/awaitme_berkin_yildirim.py b/Week05/awaitme_berkin_yildirim.py new file mode 100644 index 00000000..c1cd83dd --- /dev/null +++ b/Week05/awaitme_berkin_yildirim.py @@ -0,0 +1,17 @@ +import asyncio +from functools import wraps + +def awaitme(func): + """ + Calls the given function and awaits if it's an async function, + otherwise calls it normally. + :param func: The function to be called. + """ + @wraps(func) + async def wrapper(*args, **kwargs): + result = func(*args, **kwargs) + if asyncio.iscoroutine(result): + return await result + return result + + return wrapper